Why Do I Get "Undefined Method 'Paginate'" Error in Production

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



Leave a reply



Submit