I have my <%= will_paginate %>
code block in the layout of my application. I'd like to pass this block different collections depending on what controller/action I'm in. How can I do this?
views:
149answers:
2
A:
You can specify a collection after the will_paginate method.
In your controller:
@collection = MyTable.find(:all, :page => params[:page])
In your view:
<%= will_paginate @collection %>
Mike Sutton
2010-01-12 21:53:17
Right, but is there a way to pass dynamic collection names to will_paginate? Similar to... render :partial, :locals => { :collection => @dynamic_collection }, then in the layout... <%= will_paginate @collection %> ?
bobthabuilda
2010-01-12 21:57:13
will_paginate doesn't care about the collection name - it's a variable that conforms to the will_paginate collection behaviour.
Toby Hede
2010-01-13 00:19:50
A:
Ah ... rereading your question I see what you mean.
I think the easiest way to do this would simply to always use the same variable name, or to set a standard name with the value from your pagination query.
# Controller
@collection = Model.paginate
#OR
@entries = Entry.paginate
@collection = @entries
# View:
<%= will_paginate @collection %>
Toby Hede
2010-01-13 00:22:54
I didn't want to do it this way, but I guess it'll have to do. Thanks.
bobthabuilda
2010-01-13 04:01:57