# Repeat two blocks of code of same db under dif conditions

**URL:** <https://www.ruby-forum.com/t/repeat-two-blocks-of-code-of-same-db-under-dif-conditions/119849>\
**Category:** Rails\
**Created:** [November 11, 2007, 9:36am UTC](https://www.ruby-forum.com/t/repeat-two-blocks-of-code-of-same-db-under-dif-conditions/119849 "2007-11-11T09:36:34Z")\
**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:** [November 11, 2007, 9:36am UTC](https://www.ruby-forum.com/t/repeat-two-blocks-of-code-of-same-db-under-dif-conditions/119849/1 "2007-11-11T09:36:34Z")

</div>

I have some images connected with some db settings in my app. I want to  
get all the images from DB into two different section, one for  
screenshots and one for wallpapers. In the db, each image has an  
attribute image\_type which defines which one it is. So I thought to put  
this code into the view:

\<% @game.images.each do |screenshot| %\>  
\<% @game.images.each do |wallpaper| %\>

After some research, I found out that I didn’t actually understand what  
I was doing at the time. So how can I do it (properly and not noobish  
like I did here) and get two separate sections with each getting a bunch  
of images of a certain type??? Thx a lot -Jake
