# Beginner Question - Pagination, Each?

**URL:** <https://www.ruby-forum.com/t/beginner-question-pagination-each/84259>\
**Category:** Ruby\
**Created:** [February 2, 2007, 7:45pm UTC](https://www.ruby-forum.com/t/beginner-question-pagination-each/84259 "2007-02-02T19:45:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [February 2, 2007, 7:45pm UTC](https://www.ruby-forum.com/t/beginner-question-pagination-each/84259/1 "2007-02-02T19:45:02Z")

</div>

Many thanks to anyone willing to assist.

I have a rails database application that produces about 20 pages showing  
10 lines each. I’d like a link at the bottom to each page that looks  
like many you have seen: Go to page 1 | 2 | 3 | 4 | etc.

Tried to use the “each” method as follows:

\<%= if @member\_pages.each  
link\_to ‘Go to page \>’, { :page =\> ()}  
end  
%\>

I get an error “no block given”

The following snippet:

\<%= if @member\_pages.current.next  
link\_to ‘Next page’, { :page =\> @member\_pages.current.next }  
end  
%\>

DOES produce a link to the next page! But I didn’t figure this out. It  
was part of the tutorial. I’d appreciate any help. I bought every book  
on the subject, but I’m too new to know what I’m reading.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [February 2, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/beginner-question-pagination-each/84259/2 "2007-02-02T20:20:13Z")

</div>

On 2/2/07, David H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= if @member\_pages.each  
> link\_to ‘Go to page \>’, { :page =\> ()}  
> end  
> %\>
> 
> I get an error “no block given”

You have a basic syntax error - missing the “do” keyword:

---

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [February 2, 2007, 8:46pm UTC](https://www.ruby-forum.com/t/beginner-question-pagination-each/84259/3 "2007-02-02T20:46:53Z")

</div>

Justin B. wrote:

> On 2/2/07, David H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > \<%= if @member\_pages.each  
> > link\_to ‘Go to page \>’, { :page =\> ()}  
> > end  
> > %\>
> > 
> > I get an error “no block given”
> 
> You have a basic syntax error - missing the “do” keyword:

Thanks Justin. I dropped the conditional and tried this:

\<%= link\_to ‘Go to page \>’, { :page =\> @member\_pages.each do () end} %\>

This did not produce an error message, but it also did not produce what  
I wanted. Instead, it produced a link to the last page.

---

<div class="post-metadata">

**Author:** ![divotdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bbe5ce/32.png) [@divotdave](https://www.ruby-forum.com/u/divotdave)\
**Post date:** [February 2, 2007, 9:48pm UTC](https://www.ruby-forum.com/t/beginner-question-pagination-each/84259/4 "2007-02-02T21:48:20Z")

</div>

David H. wrote:

> Justin B. wrote:
> 
> > On 2/2/07, David H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > 
> > > \<%= if @member\_pages.each  
> > > link\_to ‘Go to page \>’, { :page =\> ()}  
> > > end  
> > > %\>
> > > 
> > > I get an error “no block given”
> > 
> > You have a basic syntax error - missing the “do” keyword:
> 
> Thanks Justin. I dropped the conditional and tried this:
> 
> \<%= link\_to ‘Go to page \>’, { :page =\> @member\_pages.each do () end} %\>
> 
> This did not produce an error message, but it also did not produce what  
> I wanted. Instead, it produced a link to the last page.

Well a few more hours of searching the web produced this excellent link.

[http://wiki.rubyonrails.org/rails/pages/HowtoPagination](http://wiki.rubyonrails.org/rails/pages/HowtoPagination)

Thanks to all from a scary beginner!
