While looping through my objects in a view I am trying to display the first attached image of my listing like this:
<%= image_tag listing.assets.first.attachment.url(:small) %>
This works fine if all my listings have at least one image but if one listing doesn't have an image, the default image is not shown. Instead I get a undefined method `attachment' for nil:NilClass.
Which is logical because the object is nil but I have this in my model
has_attached_file :attachment, :styles => { :medium => "300x300>",
:small => "200x200>", :thumb => "100x100>" }, :default_url =>
"no_image_:style.jpg"
So I assume if image_tag doesn't receive aI url it should display "no_image_small.jpg" which is in my app/assets/images folder.
Is that how it should work? How can I display my no_image_small.jpg if the image doesn't exist and is nill?