简体   繁体   English

NoMethodError:私有方法`warn'调用nil:NilClass

[英]NoMethodError: private method `warn' called for nil:NilClass

I am trying to implement server deployment for my rails app using capistrano. 我正在尝试使用capistrano为我的Rails应用程序实现服务器部署。 I am doing it for the first time. 我是第一次做。 Now, I am stuck at a NoMethodError . 现在,我陷入了NoMethodError I am not able find the issue 我找不到问题

My Gemfile contains the following gems 我的宝石文件包含以下宝石

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

Now I am getting the following error when executing the command 现在执行命令时出现以下错误

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)

170th line of /home/ruby-user/server/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/railtie.rb has the following statement /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!"

Please help me to sort it out. 请帮我整理一下。 Thank you 谢谢

It looks like you have to set the Rails.logger.warn in your application. 看来您必须在应用程序中设置Rails.logger.warn。 Try this out in the environment file 在环境文件中尝试一下

Rails.logger = Logger.new(STDOUT) Rails.logger = Logger.new(STDOUT)

I got this error and it turns out that I included a duplicate of my config.ru inside of my config/ folder. 我收到此错误,结果发现我在config /文件夹中包含config.ru的副本。 When it is there, it doesn't have access to this variable so it throws that error; 当它在那里时,它无权访问此变量,因此会引发该错误。 just delete the duplicate and it should work. 只需删除重复项即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM