Beginner Question - Pagination, Each?


#1

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!


#2

On 2/2/07, David H. 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:


#3

Justin B. wrote:

On 2/2/07, David H. 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.


#4

David H. wrote:

Justin B. wrote:

On 2/2/07, David H. 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

Thanks to all from a scary beginner!