Sunday, 15 August 2010

check If images exists in rails -


I am adding images to rail projects in this way. I want to check that the image exists and if not, then I want to use a common image for all the places where the images are not present.

Please help.

  & lt; Div class = "col-sm-2" & gt; & Lt; Center & gt; & Lt;% = image_tag pco.printable_photo.url (: small)% & gt; & Lt; Label & gt; & Lt;% = pco.name% & gt; & Lt; / Labels & gt; & Lt; / Center & gt; & Lt; / Div & gt; Type a helpful method in  application_helper.rb :  

  def print_image (url) url = Rails.application.assets.find_asset (url) .nil? ? Zero: url image_tag url || 'Default_image.jpg' end  

Then in your opinion, use it:

   

Try to avoid the logic of writing. Get help from the helpers


No comments:

Post a Comment