kaminari undefined method `page'
I've been trying to play around with the Kaminari gem for pagination, but am running into problems.
I've got a simple starter project with a simple model:
class Position < ActiveRecord::Base
validates_presence_of :name
end
I'm running with ruby 1.9.2 and rails 3.0.5 on Ubuntu 10.04. I've installed kaminari (0.10.4).
From what I understand, I should be able to execute Position.order("name").page(1), but when I do so, 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 s开发者_StackOverflow中文版eems about as simple a scenario as I can get. Any ideas would be greatly appreciated.
Thanks.
Rails noob here: had precisely the same issue but for a different reason - I found I had to restart the server after adding the kaminari gem and running bundle install. Just mentioning it in case someone else has the same problem!
I figured out my problem, and it have nothing to do with the Kaminari gem per se.
In my Gemfile, I had put the gem 'kaminari' clause under my group :test section by mistake. So it wasn't loading in my development environment. Silly mistake.
I'm also a Rails noob and had the same error. I could solve the problem by changing Model.all to Model.order("id").
精彩评论