file_column has a method which tells you whether the file has just been
uploaded or not, take a look at he source code, which has all the
documentation in it.
On 1/13/06, jeremy*pinnix <jpinnix.alt@gmail.com>
wrote:>
> 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 <null> 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
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Roberto Saccon - http://rsaccon.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060113/ff610264/attachment.html