# Displaying already stored images from the database in rails

**URL:** <https://www.ruby-forum.com/t/displaying-already-stored-images-from-the-database-in-rails/182237>\
**Category:** Rails\
**Created:** [January 25, 2010, 4:02pm UTC](https://www.ruby-forum.com/t/displaying-already-stored-images-from-the-database-in-rails/182237 "2010-01-25T16:02:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![atheeq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@atheeq](https://www.ruby-forum.com/u/atheeq)\
**Post date:** [January 25, 2010, 4:02pm UTC](https://www.ruby-forum.com/t/displaying-already-stored-images-from-the-database-in-rails/182237/1 "2010-01-25T16:02:27Z")

</div>

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:)

---

<div class="post-metadata">

**Author:** ![atheeq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@atheeq](https://www.ruby-forum.com/u/atheeq)\
**Post date:** [January 25, 2010, 4:29pm UTC](https://www.ruby-forum.com/t/displaying-already-stored-images-from-the-database-in-rails/182237/2 "2010-01-25T16:29:27Z")

</div>

> 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.
