Mind Dump, Tech And Life Blog
written by Ivan Alenko
published under license Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)copy! share!
posted at 24. Aug '21

Nil Location Provided. Can’t Build URI

ActionView::Template::Error (Nil location provided. Can't build URI.) URL cannot be nil for some URL helpers (everything which uses url_for in general) in Rails.

Solution 1: Use default cover image:

image_tag(@article.cover.url || default_cover_url)

Solution 2: Don’t show any cover image if it’s not there

<% if @article.cover %>
  image_tag(@article.cover.url)
<% end %>

Add Comment