main的局部变量或方法`config':Object(NameError)

时间:2014-06-17 20:27:13

标签: ruby-on-rails devise omniauth

我正在关注这篇关于整合Omniauth Twitter + Devise http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/的帖子,我遇到了阻止我启动rails应用程序的问题。

 /Users/javier/Desktop/definitive/config/environment.rb:8:in `<top (required)>': undefined     local variable or method `config' for main:Object (NameError)
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
from /Users/javier/Desktop/definitive/config.ru:3:in `block in <main>'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /Users/javier/Desktop/definitive/config.ru:in `new'
from /Users/javier/Desktop/definitive/config.ru:in `<main>'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/server.rb:50:in `app'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/server.rb:130:in `log_to_stdout'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/server.rb:67:in `start'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:81:in `block in server'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `tap'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `server'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/javier/Desktop/definitive/bin/rails:8:in `require'
from /Users/javier/Desktop/definitive/bin/rails:8:in `<top (required)>'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /Users/javier/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /Users/javier/Desktop/definitive/bin/spring:16:in `require'
from /Users/javier/Desktop/definitive/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

我想问题出现在config/environment.rb的第8行,但找不到合适的修复程序。是否有可能将environment.rb包含在'config / environments /'中?

3 个答案:

答案 0 :(得分:11)

文章指出你应该把一些代码放在:

config/environments/[environment].rb

[environment].rb表示以下文件之一:

config/environments/development.rb
config/environments/production.rb
config/environments/test.rb

如果您希望在不同的环境中使用相同的设置,也可以将代码放在config/application.rb中。

显示的代码行以config.*开头,它们应放在Rails.application.configure do块内。

典型的Rails 4应用程序中的

config/environment.rb只是requireRails.application.initialize!,不需要修改。

答案 1 :(得分:3)

如果config.xxx

中有environment.rb

删除它并将其添加到development.rb

Rails.application.configure do
  config.xxx
end

答案 2 :(得分:0)

我也遇到过这样的错误(

SELECT Query1.SETYPE, Query1.`SEORD#`, Query1.ORBILL, Query1.ORCUST, Query1.ORLDAT, Query1.ORCONS, Query1.SESEV, Query1.CMTYPE, Query1.CMTEXT, Query1.ORDDATfix
FROM `C:\USERS\DRED\DESKTOP\ServiceFailures.accdb`.Query1 Query1
WHERE (Query1.ORDDATfix>=?)

也许是因为我是铁轨上的红宝石新手。因此,我没有从直接命令行启动rails服务器,而是尝试从IRB内部启动,因此我收到了错误。

当我从IRB出来并再次从CMD启动服务器时,它开始顺利。