0

昨晚我在我的 web 应用程序上工作了很多,然后上床睡觉。今天起床尝试从另一台电脑访问网页,遇到以下问题:

Ruby (Rack) application could not be started

Error message:
    undefined local variable or method `config' for main:Object
Exception class:
  NameError

Backtrace:
    #   File    Line    Location
    0   /var/www/myapp/config/initializers/setup_mail.rb    1   
    1   /var/lib/gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  245     in `load'
    2   /var/lib/gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  245     in `load'
    3   /var/lib/gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  236     in `load_dependency'
    4   /var/lib/gems/1.8/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  245     in `load'
    5   /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/engine.rb  588     
    6   /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/engine.rb  587     in `each'
    7   /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/engine.rb  587     
    8   /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/initializable.rb   30  in `instance_exec'
    9   /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/initializable.rb   30  in `run'
    10  /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/initializable.rb   55  in `run_initializers'
    11  /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/initializable.rb   54  in `each'
    12  /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/initializable.rb   54  in `run_initializers'
    13  /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/application.rb     136     in `initialize!'
    14  /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/railtie/configurable.rb    30  in `send'
    15  /var/lib/gems/1.8/gems/railties-3.2.11/lib/rails/railtie/configurable.rb    30  in `method_missing'
    16  /var/www/myapp/config/environment.rb    5   
    17  config.ru   3   in `require'
    18  config.ru   3   
    19  /var/lib/gems/1.8/gems/rack-1.4.5/lib/rack/builder.rb   51  in `instance_eval'
    20  /var/lib/gems/1.8/gems/rack-1.4.5/lib/rack/builder.rb   51  in `initialize'
    21  config.ru   1   in `new'
    22  config.ru   1   

setup_mail.rb 的内容

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address              => "localhost",
  :port                 => 25,
  :domain               => 'mydomain.com',
  :openssl_verify_mode  => 'none',
  :tls                  => false,
  :enable_starttls_auto => false

}

有人能告诉我如何解决这个问题吗?当我对任何文件进行更改时,我是否需要重新启动乘客或 nginx 或我的 rails 应用程序?错误消息太神秘了,不知道在哪里寻找问题。感谢您的帮助!:)

4

1 回答 1

1

您正在尝试在适当的上下文之外访问应用程序的配置对象。尝试像这样包装您的代码:

AppName::Application.configure do
  config.action_mailer.delivery_method = :smtp
  # etc ...
end

或将每个替换configAppName::Application.config.

于 2013-03-11T21:50:14.290 回答