I am using Kaminari 0.16.3 with Rails 4.2.0. Not sure what is going wrong, I have pasted code run by me in console, which proves kaminari gem is loaded but page method is undefined on ActiveRecord model.
abhishek#abhishek ~/my_app (master●●)$ rails c [ruby-2.1.5p273]
Loading development environment (Rails 4.2.0)
irb(main):001:0> Kaminari
=> Kaminari
irb(main):002:0> User.page
NoMethodError: undefined method `page' for User (call 'User.connection' to establish a connection):Class
Please note: I am intentionally calling page without any arguments to reproduce the issue.
Due to an issue with will_paginate and rails_admin I had this in my codebase causing the page method to be renamed to per_page_kaminari.
I have realized this late and fixed.
Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
end
Have a look at this tutorial https://github.com/amatsuda/kaminari
This is how it works
User.page(page_number).per(records_per_page)
Related
I'm running into this error when upgrading from Rails 6.0.3 to 6.1:
NoMethodError:
undefined method `assert_nothing_raised' for #<RSpec::ExampleGroups::EmailJob:0x00005572d8a00758>
Did you mean? assert_raises
This happens every time a test calls perform_enqueued_jobs.
I'm using RSpec 3.9.
Apparently assert_nothing_raised is a helper method defined by ActiveSupport. I was able to solve this issue by explicitly including the helper in spec/rails_helper.rb:
RSpec.configure do |config|
config.include(ActiveSupport::Testing::Assertions)
# ...
I just installed the will_paginate, 3.0.7 and bootstrap-will_paginate, 0.0.10 gem and when i call the following to get my articles paginated
def index
#articles = Article.paginate(page: params[:page], per_page: 5)
end
I get the following error upon attempting to launch the localhost server
/Users/Jack/.rvm/gems/ruby-2.3.1#global/gems/activesupport-5.0.0.1/lib/active_support/i18n_railtie.rb:45:in `map': undefined method `existent' for #<String:0x007fd4a2bfa5d0> (NoMethodError)
Did you mean? extend
What's going wrong?
This was an issue with earlier version of will_paginate with Rails 5.
You need to update your will_paginate gem to use latest updated one which is:
gem 'will_paginate', '3.1.5'
This issue has been fixed with this merge:
https://github.com/mislav/will_paginate/pull/450
Im trying to install Kaminari pagination on rails 3 with adminpanel RailsAdmin, but I get this error:
NoMethodError in ShowsController#
undefined method `page' for # < ActiveRecord::Relation:0xaadc8d4>
Do you also have the gem "will_paginate" in use?
Check the file Gemfile.lock to see if you have this gem in use as well:
grep will_paginate Gemfile.lock
If that's the case, all you have to do is to create the file "config/initializers/kaminari.rb" and write this content on the file:
Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
end
that should fix the issue
In my case I forgot to add the kaminari gem to my Gemfile :facepalm:
I am having errors when using the where method
Project.where('projectid=10').first
It give me this :
NoMethodError: undefined method
where' for #<Class:0xb6ee1144>
from /home/rvb/2011/January/desaldata/vendor/rails/activerecord/lib/active_record/base.rb:1672:in
method_missing_without_paginate'
from /home/rvb/2011/January/desaldata/vendor/gems/mislav-will_paginate-2.3.6/lib/will_paginate/finder.rb:167:in `method_missing'
from (irb):3
I'm using Rails 2.1.1 .. Is the where method not available in this rails version?
'Where' method is only available in rails 3.0.0 or above....
If you do upgrade to Rails (or just ActiveRecord) 3.0, change your query to this:
Project.where(:projectid => 10).first
Also, change the name of 'projects'.'projectid', to 'projects'.'id'.
If a project is running Rails 2.2.2, and it uses controller.helper and the helper is not defined, then how can it be solved? (this is for the Facebooker2 gem http://github.com/mmangino/facebooker2)
details:
error shown:
=> Rails 2.2.2 application starting on http://0.0.0.0:3000
Exiting
/Library/
Ruby/
Gems/1.8/gems/facebooker2-0.0.5/lib/facebooker2/rails/controller.rb:8:
in `included': undefined method `helper' for Object:Class (NoMethodError)
The code is: error line is line 8:
controller.helper Facebooker2::Rails::Helpers
in the following code:
module Facebooker2
module Rails
module Controller
def self.included(controller)
controller.helper Facebooker2::Rails::Helpers
controller.helper_method :current_facebook_user
controller.helper_method :current_facebook_client
controller.helper_method :facebook_params
end