I want a page to display an image for a record if the image file actually exists. If the file does not exist (newly created record) I want the placeholder image to display. I''ve tried using File.exist? as my conditional but it fails to find the files that do exist. Any ideas how to easily handle this at the view code level? View Code: <% for e in @media_elements %> <% if File.exist?(e.filename) %> <%= link_to(image_tag(e.filename.to_s) -%> <% else %> <%= link_to(image_tag("placeholder_image.jpg") -%> <% end %> <% end %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Corey Murphy
2008-Nov-24 18:01 UTC
Re: Checking if Image file exists before displaying it?
Nevermind. It was a path issue, just provided some more info on the full path to the image and the File.exist? method worked just fine. Sorry for wasting the space. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---