Why do I get undefined method 'paginate' error in production?
I reinstalled the server, now it works. Don't know why...
Rails 5 : NoMethod Error - Undefined Method Paginate
Try to make sure your ApplicationController
inherits from ActionController::API
instead of ActionController::Base
. And if for some reason you can't update your controller, you can include the Rails::Pagination
module into your ApplicationController
manually.
credits
Update:
class ApplicationController
include Rails::Pagination
......
....
end
undefined method 'paginate'
Restart a server after installing a gem.
Undefined method `paginate'
will_paginate doesn't work like that. paginate
is a method of the Location
class:
def index
@locations = Location.paginate(page: params[:page], per_page: 10)
respond_to do |format|
format.html
format.json { render json: @locations }
end
end
Moreover, to use will_paginate you should just need to add the line below in your Gemfile
, no modification in environment.rb
is required:
gem "will_paginate", "~> 3.0.4"
undefined method `paginate' despite having will_paginate gem
Try .where
instead of .find_by
:
@music_wads = Wad.where(category: "Music").paginate(page: params[:page])
.find_by
returns first record matching your conditions, while .paginate
needs an ActiveRecord::Relation
collection of records to work.
will_paginate error in production NoMethodError (undefined method `page' for []:ActiveRecord::Relation):
Finally the long sleepless night is over. The recipe is:
gem update --system (on both: server and local machine)
update local ruby version, to ruby version as on server, or vice versa
cap deploy:setup (don't now if it is necessary, but it works for me)
cap deploy && cap deploy:restart
and BAMM, it works.
The problem was in ruby versions. They were different local/remote machines.
You can find this issue, answered by Mislav here: https://github.com/mislav/will_paginate/issues/308
Undefined method paginate error message is coming while using will_paginate Gem
Ah, just noticed you're on rails 3. In that case, try this instead:
@products = Product.paginate(page: params[:page], per_page: 5)
The difference is the lack of #all
, which returns an Array
on rails 3.
rails 2, Will_paginate, undefined method `paginate' for #Class:
In the past there where some problems with will_paginate and Rails 2, try to update to the latest version op will_paginate. In the meanwhile you can try this :
@products = Product.all.paginate(:page => params[:page], :per_page => 6, :conditions => ['brand_id = ? AND category_id = ?', @brand.id, @category.id])
Related Topics
Execute Code Once Sinatra Server Is Running
Ruby on Rails Workflow Engine (Like Ibm Workflow)
How to Recursively Flatten a Yaml File into a JSON Object Where Keys Are Dot Separated Strings
Rails 3: Belongs_To, Has_One and Migrations
Gem Install JSON Fails with Redifinition of Struct Timezone/Timespec
Bundler: Not Executable: Script/Delayed_Job
Empty Strings at the Beginning and End of Split
Rescuing "Command Not Found" for Io::Popen
Permanently Switching User in Capistrano 3 (Separate Authorization & Deploy)
How to Http Post Stream Data from Memory in Ruby
Wicked_Pdf Is Not Rendering Header
Ruby 1.9 - No Such File to Load 'Win32/Open3'
Ruby Range: Operators in Case Statement
Validating Phone Number in Ruby
Ternary Expression with "Defined" Returns "Expression" Instead of Value