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.
813b610ffda5785980cfb11c85bad617?d=identicon&s=25 David Heacock (kemperkode)
on 2007-02-02 19: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!
573b9499030e1ccb867ef80f0ff1ac49?d=identicon&s=25 Justin Bailey (Guest)
on 2007-02-02 20:20
(Received via mailing list)
On 2/2/07, David Heacock <deheacock@earthlink.net> 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:
813b610ffda5785980cfb11c85bad617?d=identicon&s=25 David Heacock (kemperkode)
on 2007-02-02 20:46
Justin Bailey wrote:
> On 2/2/07, David Heacock <deheacock@earthlink.net> 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.
813b610ffda5785980cfb11c85bad617?d=identicon&s=25 David Heacock (kemperkode)
on 2007-02-02 21:48
David Heacock wrote:
> Justin Bailey wrote:
>> On 2/2/07, David Heacock <deheacock@earthlink.net> 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.