gpt4 book ai didi

ruby-on-rails - 为什么在生产中出现 "undefined method ' paginate'"错误?

转载 作者:数据小太阳 更新时间:2023-10-29 07:25:51 26 4
gpt4 key购买 nike

在生产服务器上使用 will_paginate 时出现此错误:

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'

这是我在 Controller 中使用它的方式:

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

我的观点是:

<%= will_paginate @meals %>

我已经尝试过“will_paginate error in production NoMethodError (undefined method `page' for []:ActiveRecord::Relation)”和the same question on GitHub中建议的解决方案但它没有用。我还检查了服务器和本地是否安装了相同的 Ruby。

这在开发中有效。服务器设置是:Ubuntu 12.10、Nginx、 unicorn 、Capistrano、Ruby 2.0.0p247、Rails 4.0.0。有什么建议吗?

我的 gemfile 是:

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 是:

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

更新:我重新安装了服务器,现在可以使用了。不知道为什么...

最佳答案

我重新安装了服务器,现在可以使用了。不知道为什么...

关于ruby-on-rails - 为什么在生产中出现 "undefined method ' paginate'"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19577344/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com