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:)
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:)
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs