views:

149

answers:

2

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?

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
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
will_paginate doesn't care about the collection name - it's a variable that conforms to the will_paginate collection behaviour.
Toby Hede
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
I didn't want to do it this way, but I guess it'll have to do. Thanks.
bobthabuilda