2013-04-28 59 views
1

我正在使用will_paginate gem来处理类似Ajax的“see-more”链接。它在开发中工作,但在生产中失败。will_paginate生产中的错误NoMethodError(未定义的方法'页面'为[]:ActiveRecord :: Relation):

在我的生产日志,我得到:

NoMethodError (undefined method `page' for []:ActiveRecord::Relation): 

我试过,在生产应用程序根目录键入:

grep will_paginate Gemfile.lock 

,并得到:

will_paginate (3.0.4) 
will_paginate 

帽包:安装不会失败在我的VPS上安装will_paginate,但是当我试图明确要求'will_paginate'时,它的钢铁在开发并在生产失败,但这次是整个网站,而不仅仅是我使用过的行动will_paginate。这需要触发unicorn.log错误:

No such file to load will_paginate (LoadError) 

所以我认为will_paginate不instals他的目录,在我的VPS正确王氏捆绑安装,但为什么呢?

我试着输入:

gem list 

而且在没有will_paginate。所以我明确地说,在我目前的应用程序目录中。 gem install will_paginate 而且这也没有解决问题。

所以我 宝石卸载will_paginate 和 “帽部署” 再次 后,我再次 宝石列表 ,再次出现在没有will_paginate

的Gemfile:

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

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, "[email protected]:........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 

结束

任何人都可以帮助我解决这个问题吗?

或者也许有人知道如何显式添加will_paginate所需的所有文件到rails应用程序。所以它会工作没有宝石will_paginate

我绑:

bundle exec gem list 

,并在列表中查找will_paginate(3.0.4)。这意味着它已安装,但不适用于我的应用程序?

+0

你可以给你用来部署帽脚本? – suman 2013-04-28 14:54:45

+0

好的。我把它添加到我的问题 – 2013-04-28 16:09:14

回答

0

最后,漫长的不眠之夜已经结束。配方是:

gem update --system (on both: server and local machine) 

更新本地红宝石版本,红宝石版本的服务器,反之亦然

cap deploy:setup (don't now if it is necessary, but it works for me) 
cap deploy && cap deploy:restart 

和BAMM,它的工作原理。

问题出在红宝石版本。他们是不同的本地/远程机器。

你可以找到这个问题,通过Mislav在这里找到答案:https://github.com/mislav/will_paginate/issues/308

相关问题