Rails在environment.rb中未定义方法`Initialize'

时间:2012-04-24 01:28:51

标签: ruby-on-rails ruby-on-rails-3

我正在尝试将twitter / bootstrap集成到我的第一个rails应用程序中(遵循本文http://www.opinionatedprogrammer.com/2011/11/twitter-bootstrap-on-rails/),现在我收到此错误,我无法理解/解决。


    new-host:Talker Talker$ rails s
=> Booting Thin
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Projects/Talker/config/environment.rb:4:in <top (required)>': undefined methodInitialize' for Rails:Module (NoMethodError)
    from /Projects/Talker/config.ru:4:in require'
    from /Projects/Talker/config.ru:4:inblock in '
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:51:in instance_eval'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:51:ininitialize'
    from /Projects/Talker/config.ru:1:in new'
    from /Projects/Talker/config.ru:1:in'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:40:in eval'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:40:inparse_file'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:200:in app'
    from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/server.rb:46:inapp'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:301:in wrapped_app'
    from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:252:instart'
    from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/server.rb:70:in start'
    from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:55:inblock in '
    from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:50:in tap'
    from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:50:in'
    from script/rails:6:in require'
    from script/rails:6:in'
这就是我的environments.rb的样子
<top (required)>': undefined method

我对rails很新,所以非常感谢任何帮助/方向!

2 个答案:

答案 0 :(得分:1)

我认为你不需要在Rails.Initialize中指定config.gem。在项目根目录下的Gemfile中指定gems。您可以删除上述

gem "mongo"
gem "mongo_mapper"

然后使用bundle install安装gems。现在你应该拥有宝石

请在删除Rails.Initialize块

后尝试重新启动

答案 1 :(得分:1)

按照naren的说明操作时,您是否从Rails.Initialize.run文件中删除了environment.rb块?我知道这可能听起来很傻:)

此外,从第二个错误,我收集到您可能正在使用Mongo HQ,如果它是在Heroku上托管的,他们有一个非常详细的配置数据库的使用说明书。 Heroku MongoHQ Dev Center。在您的应用中检查两件事:

  1. 是否正确配置了MongoDB网址(Mongo HQ的网址)?这是因为,第二个错误表明链接本身可能存在问题。

  2. 较新版本的rails(3及更高版本)不允许环境块中的config.gem语法。相反,您需要在config/initializers中添加初始化文件。有关详情,请参阅MongoDB Documentation for Rails 3部分。

  3. 希望这有帮助。