# Help With Loop please

**URL:** <https://www.ruby-forum.com/t/help-with-loop-please/106669>\
**Category:** Rails\
**Created:** [June 13, 2007, 2:27am UTC](https://www.ruby-forum.com/t/help-with-loop-please/106669 "2007-06-13T02:27:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bxsitecover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bxsitecover](https://www.ruby-forum.com/u/bxsitecover)\
**Post date:** [June 13, 2007, 2:27am UTC](https://www.ruby-forum.com/t/help-with-loop-please/106669/1 "2007-06-13T02:27:57Z")

</div>

New to rails! Thanks for reading

I have a database that stores link URL’s and their names in one  
table.

DB Table is named: links

Model name : Link

Controller: admin

Links are stored in the “link\_url” column  
Their names are stored in the “title” column  
They all are assigned an ID on auto increment.

What I want to do is display 10 links at a time out of (50+ links)  
And be able to rotate the links on a weekly basis, and display that in  
a partial.

Can anyone help me with this timed loop to display 10 links at a time  
from my db? Or refer me to a chapter in a rails book. Thanks!

This is the default code to display them all.

\<% for link in @links -%\>

\<%= h(link.title) %\>
\<% end %\>

---

<div class="post-metadata">

**Author:** ![bxsitecover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bxsitecover](https://www.ruby-forum.com/u/bxsitecover)\
**Post date:** [June 13, 2007, 5:31am UTC](https://www.ruby-forum.com/t/help-with-loop-please/106669/2 "2007-06-13T05:31:10Z")

</div>

How about selecting a range based on the day of month (so you can show  
a different subset of @links based on what week of the month you’re  
in).

Something like:

case Time.now.day  
when 1…7  
range = 0…10  
when 8…14  
range = 11…20  
when 15…21  
range = 21…30  
else  
range = 31…50  
end

\<% @links[range].each do |link| %\>

- Ben

[http://www.ticketi.sh/](http://www.ticketi.sh/)  
Simple Help Ticket Tracking for People Who Want Less

On 6/13/07, bxsitecover [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
…

> What I want to do is display 10 links at a time out of (50+ links)  
> And be able to rotate the links on a weekly basis, and display that in  
> a partial.
> 
> Can anyone help me with this timed loop to display 10 links at a time  
> from my db? Or refer me to a chapter in a rails book. Thanks!  
> …
