will_paginate: undefined local variable or method `per' for []:ActiveRecord::Relation
Hello, After adding will_paginate to my Gemfile I get this error:
gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git'
undefined local variable or method `per' for []:ActiveRecord::Relation
Rails.root: /home/slava/dev/projects/bitcoin-derivatives
Application Trace | Framework Trace | Full Trace
activerecord (3.1.0) lib/active_record/relation.rb:459:in `method_missing'
/home/slava/.rvm/gems/ruby-1.9.2-p290/bundler/gems/spree-037b9258f970/core/lib/spree/search/base.rb:15:in `retrieve_products'
/home/slava/.rvm/gems/ruby-1.9.2-p290/bundler/gems/spree-037b9258f970/core/app/controllers/home_controller.rb:7:in `index'
About this issue
- Original URL
- State: closed
- Created 13 years ago
- Comments: 31 (2 by maintainers)
Commits related to this issue
- fixed issue: https://github.com/radar/forem/issues/183#issuecomment-6334720, see: https://github.com/mislav/will_paginate/issues/174#issuecomment-4475139. — committed to jarray52/forem by nebiros 12 years ago
- Fix for workaround for kaminara / will_paginate conflict See https://github.com/mislav/will_paginate/issues/174#issuecomment-4475139 — committed to openaustralia/planningalerts by mlandauer 5 years ago
Actually this solution ain’t working anymore, if you still want to use will_paginate instead of kaminari you will have to modify your initializer to this :
Thank you @andrewroth for the tip.
Just an FYI, this was broke for me as well when using
activeadminwhich requires Kaminari which happens to conflict with my existing version ofwill_paginate -v3.0.2. I found a similar issue here which described a workaround. What fixed it for me was to add an initializer to handle conflicting methods:I’m using RefineryCMS with Spree Commerce. Here’s what my dependencies look like:
I put the following in
config/initializers/kaminari_config.rbto solve this problem:If any of you have an extra issue with the a method known as ‘total count’, try this modified initializer:
Actually ctiveAdmin uses Kaminari for pagination We have used will_paginate in your app, due to that pagination get conflict, to remove this conflicts. Just create kaminari.rb file in your “config/initializers/kaminari.rb”
and type this code in it.
Kaminari.configure do |config| config.page_method_name = :per_page_kaminari end
Restart the server again and hope the issue get resolved.
I solved this problem by adding
ruby Spree::Product::ActiveRecord_Relation.include Kaminari::PageScopeMethodsto config/initializers/kaminari.rb
Spree replaced will_paginate with Kaminari and now is using its methods, one of which is
perinstead ofper_page.Since will_paginate and Kaminari are not compatible, you should remove it from your Gemfile.