[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Beginner Question - Pagination, Each?

David Heacock

2/2/2007 6:45:00 PM

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!

--
Posted via http://www.ruby-....

3 Answers

jgbailey

2/2/2007 7:20:00 PM

0

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:

> <%= if @member_pages.each do
> link_to 'Go to page >', { :page => ()}
> end
> %>

David Heacock

2/2/2007 7:47:00 PM

0

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.


--
Posted via http://www.ruby-....

David Heacock

2/2/2007 8:48:00 PM

0

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/Howto...

Thanks to all from a scary beginner!

--
Posted via http://www.ruby-....