Ruby/Rails - kaminari undefined method pagination errors

johnnycakes picture johnnycakes · Aug 2, 2011 · Viewed 8.9k times · Source

I'm not sure what I did, but kaminari has started acting weird in my app.

In my controller:

@producers = Producer.order(:name).page(params[:page])

view:

<%= paginate @producers %>

results in:

undefined method `num_pages' for #<ActiveRecord::Relation:0x000001026e6308>

If I add .per in my controller:

@producers = Producer.order(:name).page(params[:page]).per(25)

I get

undefined local variable or method `per' for #<ActiveRecord::Relation:0x0000010928ef60>

Finally, strangely, if I move my .order(:name) to the end, it works:

@producers = Producer.page(params[:page]).order(:name)

I'm guessing some other gem I have installed has a page scope or method that's causing problems?

Thanks.

Answer

johnnycakes picture johnnycakes · Aug 3, 2011

Well, just figured it out. I had Active Admin installed. It installed will_paginate as a dependency.

In the latest commits for Active Admin, will_paginate has been replaced with kaminari.

I changed my Gemfile to pull Active Admin from github. will_paginate was removed from my bundle and now everything works. You can do this by putting the following line into your gemfile:

gem "activeadmin", git: "https://github.com/gregbell/active_admin"