Rails undefined method `Initialize' in environment.rb
我正在尝试将twitter / bootstrap集成到我的第一个rails应用程序中(遵循这篇文章http://www.opinionatedprogrammer.com/2011/11/twitter-bootstrap-on-rails/),现在我收到此错误,我是 无法理解/解决。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 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 <wyn><top (required)>': undefined method</wyn>Initialize' for Rails:Module (NoMethodError) from /Projects/Talker/config.ru:4:in <wyn>require' from /Projects/Talker/config.ru:4:in</wyn>block in ' from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:51:in <wyn>instance_eval' from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:51:in</wyn>initialize' from /Projects/Talker/config.ru:1:in <wyn>new' from /Projects/Talker/config.ru:1:in</wyn>' from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:40:in <wyn>eval' from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:40:in</wyn>parse_file' from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:200:in <wyn>app' from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/server.rb:46:in</wyn>app' from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:301:in <wyn>wrapped_app' from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:252:in</wyn>start' from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/server.rb:70:in <wyn>start' from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:55:in</wyn>block in ' from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:50:in <wyn>tap' from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:50:in</wyn>' from script/rails:6:in <wyn>require' from script/rails:6:in</wyn>' |
代码>
这就是我的environments.rb的样子
1 2 3 4 5 6 | require File.expand_path('../application', FILE) Rails.Initialize.run do |config| config.gem 'mongo' config.gem"mongo_mapper" end Talker::Application.initialize! |
代码>
我对rails很新,所以任何帮助/方向都非常感谢!
按照naren的说明,您是否从
此外,从第二个错误,我收集到您可能正在使用Mongo HQ,如果它是在Heroku上托管的,他们有一个非常详细的配置数据库的说明手册。 Heroku MongoHQ开发中心。在您的应用中检查两件事:
是否正确配置了MongoDB网址(Mongo HQ的网址)?这是因为,第二个错误表明链接本身可能存在问题。
较新版本的rails(3及更高版本)不允许环境块中的
希望这可以帮助。
我认为你不需要在Rails.Initialize中指定config.gem。在项目根目录下的Gemfile中指定gems。你可以删除上面的内容
1 2 | gem"mongo" gem"mongo_mapper" |
然后使用bundle install安装gem。现在你应该拥有宝石
删除Rails.Initialize块后请尝试重新启动