# Selecting images from db according to type

**URL:** <https://www.ruby-forum.com/t/selecting-images-from-db-according-to-type/116615>\
**Category:** Rails\
**Created:** [October 8, 2007, 12:38am UTC](https://www.ruby-forum.com/t/selecting-images-from-db-according-to-type/116615 "2007-10-08T00:38:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakedgr8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jakedgr8](https://www.ruby-forum.com/u/jakedgr8)\
**Post date:** [October 8, 2007, 12:38am UTC](https://www.ruby-forum.com/t/selecting-images-from-db-according-to-type/116615/1 "2007-10-08T00:38:50Z")

</div>

Ok so this seems easy huh? So I have some images in a db. Some are  
marked as “screenshots” and others as “wallpapers”. Now in various parts  
of the site, I want to show only “screenshots” and in another area, only  
“wallpapers”. In the db, it’s in the column marked “image\_type” Here is  
what I thought:

The view:

\<% for screenshot in @game.images %\>  
[![<%= screenshot.id %>](https://www.ruby-forum.com/images/games/<%=%20screenshot.id%20%>-thumb.<%=%20screenshot.extension%20%> "<%= screenshot.name %>")](https://www.ruby-forum.com/images/games/<%=%20screenshot.id%20%>-full.<%=%0Ascreenshot.extension%20%>)\<% end %\>

and

\<% for wallpaper in @game.images %\>  
[![](https://www.ruby-forum.com/images/games/<%=%20wallpaper.id%20%>-thumb.<%=%20wallpaper.extension%20%>)](https://www.ruby-forum.com/images/games/<%=%20wallpaper.id%20%>-full.<%=%20wallpaper.extension%0A%>)\<% end %\>

The Models:

now I have “belongs\_to :games” and “has\_many :images”

The Controller:

@game = Game.find(params[:id])  
@images = Image.find(:all)  
@screenshot = Image.find(:all, :conditions =\> “image\_type =  
‘Screenshots’”)  
@wallpaper = Image.find(:all, :conditions =\> “image\_type =  
‘Wallpapers’”)

now how do I do it, so that it selects only the images I want? Because  
instead of selecting the image I want, it selects ALL the images for  
both. Please help people, I’m so lost… I think the answer is  
really easy, but I’m still learning rails, so be kind 😛

- Jake
