昨晚我在我的webapp上工作了很多,然后上班睡觉了。今天我醒来并尝试从另一台计算机访问该网页,遇到了以下问题:
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应用程序?错误消息太神秘了,无法知道在哪里查找问题。 谢谢您的帮助! :)
答案 0 :(得分:1)
您正在尝试在适当的上下文之外访问应用程序的配置对象。尝试包装代码如下:
AppName::Application.configure do
config.action_mailer.delivery_method = :smtp
# etc ...
end
或用config
替换每个AppName::Application.config
。