Atheeq Pasha
2010-Jan-25 15:02 UTC
Displaying already stored images from the database in rails
Hello, Can anyone tell me how to display images which are already stored in database? I have a table in which one column stores the url of the image like usrimg/xxx.gif. How to display this images in view? Thanks in advance:) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Alpha Blue
2010-Jan-25 15:29 UTC
Re: Displaying already stored images from the database in rails
> Can anyone tell me how to display images which are already stored in > database? > I have a table in which one column stores the url of the image like > usrimg/xxx.gif. How to display this images in view?If your controller was named pages_controller.rb you would do: def index @pages = Page.all end In the index.html.erb view you would do: (if your table field for the image url was named image_url) <% @pages.each do |page| %> <%= image_tag(page.image_url) %> <% end %> If you want to apply specific formatting for your images and it''s going to be repetitive, you could simply create a helper to do the formatting for you and call the helper method in the view. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.