I am using the excellent file_column, but have run into an issue.
I am wanting the user to be able to not upload an image if they so
choose. Then I am trying to determine if that column is empty or not,
and display a generic image if that column is empty.
I have tried both of the following code blocks:
<% if @newsentry.image -%>
<%= link_to(image_tag((url_for_image_column “newsentry”, “image”,
:small), :size => “50x50”, :border => 0, :class =>“news_photo”),
:controller => ‘news’, :action => ‘article’, :id => @newsentry) %>
<% else -%>
<%= link_to(image_tag("/images/news/photo_news_sm.jpg", :size =>
“50x50”, :border => 0, :class =>“news_photo”), :controller =>
‘@newsentry’, :action => ‘article’, :id => @newsentry) %>
<% end -%>
and
<% if (! @newsentry.image.nil?) and (@newsentry.image.length > 0) -%>
<%= link_to(image_tag((url_for_image_column “newsentry”, “image”,
:small), :size => “50x50”, :border => 0, :class =>“news_photo”),
:controller => ‘news’, :action => ‘article’, :id => @newsentry) %>
<% else -%>
<%= link_to(image_tag("/images/news/photo_news_sm.jpg", :size =>
“50x50”, :border => 0, :class =>“news_photo”), :controller =>
‘@newsentry’, :action => ‘article’, :id => @newsentry) %>
<% end -%>
Either way I get the error:
“cannot convert nil into String”
and it is failing here:
./script/…/config/…/vendor/plugins/file_column/lib/magick_file_column.rb:47:in
`exists?’
which tells me that it thinks the if statement is true, but then when
file_column tries to test its existence that it fails…
I looked in the db, and that field is indeed on the ones that
didn’t have files uploaded.
What is the proper way to test this?
BTW, when I remove entries that don’t have an image uploaded, it
works just fine…
Thanks,
jeremy