Why do I get “undefined method 'paginate'” error in production?

烂漫一生 提交于 2019-12-01 20:53:33

问题


I get this error when using will_paginate on production server:

I, [2013-10-24T20:17:40.386696 #18564]  INFO -- : Started GET "/meals" for 190.273.432.55 at 2013-10-24 20:17:40 +0000
I, [2013-10-24T20:17:40.388972 #18564]  INFO -- : Processing by MealsController#index as HTML
I, [2013-10-24T20:17:40.395022 #18564]  INFO -- : Completed 500 Internal Server Error in 6ms
F, [2013-10-24T20:17:40.396720 #18564] FATAL -- :
NoMethodError (undefined method `paginate' for #<ActiveRecord::Relation::ActiveRecord_Relation_Meal:0x00000005080598>):
  app/controllers/meals_controller.rb:5:in `index'

This is how I use it in the controller:

@meals = current_user.meals.order("created_at DESC").paginate(:page => params[:page], :per_page => 6)

My view is:

<%= will_paginate @meals %>

I already tried the solution suggested in "will_paginate error in production NoMethodError (undefined method `page' for []:ActiveRecord::Relation)" and the same question on GitHub but it didn't work. I also checked that server and local have the same Ruby installation.

This works in development. The server setup is: Ubuntu 12.10, Nginx, Unicorn, Capistrano, Ruby 2.0.0p247, Rails 4.0.0. Any suggestions?

My gemfile is:

source 'https://rubygems.org'

gem 'rails', '4.0.0'

gem 'zurb-foundation', '~> 4.0.0'
gem "figaro"
gem 'will_paginate', '~> 3.0.5'
gem 'carrierwave'
gem 'mini_magick'
gem 'bcrypt-ruby', '~> 3.0.0'

gem 'unicorn'
gem 'capistrano'
gem 'rvm-capistrano'

group :development, :test do
  gem 'sqlite3'
  gem 'rspec-rails', '~> 2.0'
  gem 'fabrication'
  gem 'faker'
end

group :test do
  gem "shoulda-matchers"
end

group :production do
  gem 'pg'
end

gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'

Deploy.rb is:

require "bundler/capistrano"
require "rvm/capistrano"

server "xxxx", :web, :app, :db, primary: true

set :application, "xxxx"
set :user, "xxxx"
set :port, xxxx
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "git@github.com:xxxx/#{application}.git"
set :branch, "master"


default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup" # keep only the last 5 releases

namespace :deploy do
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"

  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: :web do
    unless `git rev-parse HEAD` == `git rev-parse origin/master`
      puts "WARNING: HEAD is not the same as origin/master"
      puts "Run `git push` to sync changes."
      exit
    end
  end
  before "deploy", "deploy:check_revision"
end

UPDATE: I reinstalled the server, now it works. Don't know why...


回答1:


I reinstalled the server, now it works. Don't know why...




回答2:


I had a similar issue while working on a new rails 5 app.

I tried restarting the server but without success. What fixed it was restarting the spring server (after stopping other rails processes):

$ spring stop

then I restarted the rails server and everything worked again!




回答3:


I would try with different versions of gem, if that does not work try to add

require 'will_paginate'

in meals_controller.rb

also you can try do a fresh install of all of your gems.

bundle clean --force
bundle install

good luck!




回答4:


Try this instead:

restarting the web server worked for me!

First quit the web server by typing  "Control c" on your terminal and then

$ rails server

after that go to your http://localhost:3000 on your web browser, and you should be fine now!



来源:https://stackoverflow.com/questions/19577344/why-do-i-get-undefined-method-paginate-error-in-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!