bookaka
bookaka

Reputation: 21

Rails how create a fallback helper?

I'm trying to create a fallback helper for a object but on the page just shows the image broken link and the assets url. so, know how?

def display_image(pdata)  
    unless pdata.nil? 
      image_tag(pdata.image) 
    else
      image_tag("/assets/fallback/small_foto.png")
     end    
end

Upvotes: 0

Views: 467

Answers (1)

chrisxrobertson
chrisxrobertson

Reputation: 775

I think it is an issue with how you're organising and referencing your assets. From the Rails docs:

In regular views you can access images in the app/assets/images directory like this:

<%= image_tag "rails.png" %>

And if you want to use the custom fallback folder:

Images can also be organized into subdirectories if required, and then can be accessed by specifying the directory's name in the tag:

<%= image_tag "icons/rails.png" %>

So, move your fallback folder into assets/images and reference it with:

<%= image_tag "fallback/small_foto.png" %>

Upvotes: 1

Related Questions