Search code examples
ruby-on-railsrubyrubygemsruby-on-rails-pluginswill-paginate

Rails - Passing a collection to the layout for will_paginate?


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?


Solution

  • 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 %>