生产NoMethodError中的will_paginate错误([]:ActiveRecord :: Relation的未定义方法“页面”): [英] will_paginate error in production NoMethodError (undefined method `page' for []:ActiveRecord::Relation):
问题描述
我正在将will_paginate gem用于类似于ajax的查看更多链接。它在开发中起作用,但在生产中失败。
I'm using will_paginate gem for ajax-like "see-more" link. It works in development but fails in production.
在生产日志中,我得到:
In my production log I get:
NoMethodError (undefined method `page' for []:ActiveRecord::Relation):
我尝试过,生产应用程序键入:
I've tried, in root of production app to type:
grep will_paginate Gemfile.lock
并获得:
will_paginate (3.0.4)
will_paginate
cap bundle:install不会在我的VPS上安装will_paginate失败,但是当我尝试显式地要求'will_paginate'它在开发中起作用,但在生产中失败,但是这次是整个站点,不仅是我使用过will_paginate的动作。这需要在unicorn.log中触发错误:
cap bundle:install don't fails installing will_paginate on my VPS, but when I tried to explicitly require 'will_paginate' it steel works in development and fails in production, but this time the whole site, not only action in which I've used will_paginate. This requiring triggered an error in unicorn.log:
No such file to load will_paginate (LoadError)
所以我认为will_paginate不能通过捆绑安装将他的目录正确安装在我的VPS上,但是为什么?
So I think that will_paginate don't instals his directories on my VPS properly wih bundle install, but why?
我尝试输入:
gem list
,并且没有will_paginate。所以我明确地在我当前的应用程序目录中。
gem install will_paginate
,这也无法解决问题。
and there where no will_paginate. So I explicitly, in my current app dir. gem install will_paginate and that also didn't resolve the issue.
所以我
gem install will_paginate
和在我再次
宝石列表
之后再次盖帽部署
,然后又没有will_paginate
So I gem uninstall will_paginate and "cap deploy" again after I again gem list and again there where no will_paginate
gem 'rails', '3.2.13'
gem 'pg'
gem 'will_paginate'
gem 'sass-rails'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'devise'
gem 'uglifier'
gem 'coffee-rails'
gem "haml"
gem 'twitter-bootstrap-rails'
gem 'bootstrap-addons-rails'
gem 'bootstrap-wysihtml5-rails'
gem 'therubyracer'
gem 'less-rails'
#deploy
gem 'unicorn'
gem 'capistrano'
gem "rmagick"
gem "carrierwave"
gem 'jquery-fileupload-rails'
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem 'factory_girl_rails'
gem 'capybara'
gem 'guard-rspec'
gem 'growl'
gem 'guard-spork'
gem 'spork'
gem 'rb-fsevent', '~> 0.9'
gem "faker"
end
deploy.rb
deploy.rb
require "bundler/capistrano"
server ".....", :web, :app, :db, primary: true
set :application, "......"
set :user, "......."
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :shared_children, shared_children + %w{public/uploads}
set :scm, "git"
set :repository, "git@github.com:........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
namespace :assets do
task :precompile, :roles => :web do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0
run_locally("rake assets:clean && rake assets:precompile")
run_locally "cd public && tar -jcf assets.tar.bz2 assets"
top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
run_locally "rm public/assets.tar.bz2"
run_locally("rake assets:clean")
else
logger.info "Skipping asset precompilation because there were no asset changes"
end
end
task :symlink, roles: :web do
run ("rm -rf #{latest_release}/public/assets &&
mkdir -p #{latest_release}/public &&
mkdir -p #{shared_path}/assets &&
ln -s #{shared_path}/assets #{latest_release}/public/assets")
end
end
%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"
#rake seed task
desc "Seed the database on already deployed code"
task :seed, :only => {:primary => true}, :except => { :no_release => true } do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:seed"
end
desc "Seed the database on already deployed code"
task :drop, :only => {:primary => true}, :except => { :no_release => true } do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:drop:all"
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:create:all"
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:migrate"
end
end
有人可以帮我解决这个问题吗?
Can anyone help me with this issue?
也许有人知道如何将will_paginate所需的所有文件显式添加到rails应用程序。因此,它将在没有gem will_paginate的情况下工作
Or maybe Someone knows how to explicitly add all files, needed for will_paginate, to rails app.? So it will work without gem will_paginate
我绑定到:
bundle exec gem list
,然后在列表中找到will_paginate(3.0.4)。
and in the list a find will_paginate (3.0.4). It means that it is installed but not for my app?
推荐答案
最后漫长的不眠之夜终于过去了。配方为:
Finally the long sleepless night is over. The recipe is:
gem update --system (on both: server and local machine)
将本地Ruby版本更新为服务器上的Ruby版本,反之亦然
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
和BAMM,它可以工作。
and BAMM, it works.
问题出在红宝石版本中。它们是不同的本地/远程计算机。
The problem was in ruby versions. They were different local/remote machines.
您可以找到此问题,Mislav在这里回答: https://github.com/mislav/will_paginate/issues/308
You can find this issue, answered by Mislav here: https://github.com/mislav/will_paginate/issues/308
这篇关于生产NoMethodError中的will_paginate错误([]:ActiveRecord :: Relation的未定义方法“页面”):的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!