我正在尝试使用capistrano为我的rails应用程序实现服务器部署。我是第一次这样做。现在,我陷入了 NoMethodError 。我找不到问题
我的Gemfile包含以下宝石
group :development do
gem 'capistrano', require: false
gem 'capistrano3-puma', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano-rbenv', require: false
end
application.rb中
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Server
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
end
end
现在我在执行命令
时收到以下错误 cap production deploy
deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
01 (in /home/ruby-user/server)
01 rake aborted!
01 NoMethodError: private method `warn' called for nil:NilClass
01 /home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/railtie.rb:170:in `build_environment'
01 /home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/railties-5.2.0/lib/rails/railtie.rb:190:in `public_send'
01 /home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/railties-5.2.0/lib/rails/railtie.rb:190:in `method_missing'
01 /home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:21:in `environment'
01 /home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:42:in `cached'
01 /home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:46:in `manifest'
01 /home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:143:in `with_logger'
01 /home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in d…
01 /home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
01 /home/ruby-user/.rbenv/versions/2.5.0/bin/bundle:23:in `load'
01 /home/ruby-user/.rbenv/versions/2.5.0/bin/bundle:23:in `<main>'
01 Tasks: TOP => assets:precompile
01 (See full trace by running task with --trace)
/home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/railtie.rb的第170行有以下声明
::Rails.logger.warn "Application uninitialized: Try calling YourApp::Application.initialize!"
请帮我解决一下。谢谢
答案 0 :(得分:0)
看起来您必须在应用程序中设置Rails.logger.warn。在环境文件
中试试这个Rails.logger = Logger.new(STDOUT)
答案 1 :(得分:0)
我收到此错误,结果发现我在config /文件夹中包含config.ru的副本。当它在那里时,它无权访问此变量,因此会引发该错误。只需删除重复项就可以了。
答案 2 :(得分:0)
您需要通过运行 export RAILS_ENV=<-- environment_name -->
执行此操作,然后继续您的部署步骤。