5

I'm trying using the Kaminari pagination to have a box where a user can set how many items per page to display. I have an issue with it because I'm getting the error `undefined method to_i' for :limit:Symbol Did you mean? to_s

I set up this in a next way:

Controller:

def index
    @books = Book.order(:name).page(params[:page]).per(:limit)
  end

View:

<div class="pull-left">
    <%= form_tag controller_name, method: :get, id: 'limit_form' do %>
        <div class="select-tag">
          Show <%= select_tag :limit, options_for_select([5, 10, 15, 20], selected: params[:limit] || 10), onchange: "$('#limit_form').submit();" %> documents per page
        </div>
    <% end %>
  </div>
Jakub
  • 2,367
  • 6
  • 31
  • 82

1 Answers1

6

I think you forgot to reference params - your controller method doesn't know what :limit is, since it's just a key in your params.

Instead of this:

.per(:limit)

try this:

.per(params[:limit])
drosboro
  • 447
  • 2
  • 8