Kaminari undefined method `page '

I try to play with Kaminari stone for pagination, but I have problems.

I have a simple start-up project with a simple model:

class Position < ActiveRecord::Base validates_presence_of :name end 

I am working with ruby ​​1.9.2 and rails 3.0.5 on Ubuntu 10.04. I installed kaminari (0.10.4).

From what I understand, I would have to execute Position.order ("name"). page (1), but when I do this, I get the following:

 ruby-1.9.2-p0 > Position.order("name").page(1) NoMethodError: undefined method `page' for #<ActiveRecord::Relation:0xaacab34> from /home/bob/.rvm/gems/ ruby-1.9.2-p0@talentskout /gems/activerecord-3.0.5/lib/active_record/relation.rb:371:in `method_missing' from (irb):2 from /home/bob/.rvm/gems/ ruby-1.9.2-p0@talentskout /gems/railties-3.0.5/lib/rails/commands/console.rb:44:in `start' from /home/bob/.rvm/gems/ ruby-1.9.2-p0@talentskout /gems/railties-3.0.5/lib/rails/commands/console.rb:8:in `start' from /home/bob/.rvm/gems/ ruby-1.9.2-p0@talentskout /gems/railties-3.0.5/lib/rails/commands.rb:23:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>' 

This seems like a simple script that I can get. Any ideas would be greatly appreciated.

Thanks.

+4
source share
3 answers

Rails noob here: had exactly the same problem, but for another reason - I found that I had to restart the server after adding the kaminari stone and installing the package. Just mention this if someone else has a problem.

+16
source

I understood my problem, and it has nothing to do with Kaminari stone as such.

In my Gemfile, I put the gem "kaminari" sentence under my group: the test section by mistake. So it was not loading in my development environment. Stupid mistake.

+4
source

I am also a Rails noob and had the same error. I could solve the problem by changing Model.all to Model.order ("id").

+1
source

Source: https://habr.com/ru/post/1344857/


All Articles