Forum: Ruby Beginner Question - Pagination, Each?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
David H. (Guest)
on 2007-02-02 20:45
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!
Justin B. (Guest)
on 2007-02-02 21:20
(Received via mailing list)
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:
David H. (Guest)
on 2007-02-02 21:46
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.
David H. (Guest)
on 2007-02-02 22:48
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!
This topic is locked and can not be replied to.