Rails的未定义方法`env':模块

时间:2010-02-05 13:26:59

标签: ruby-on-rails

我想和RoR一起测试mongodb的水域。我正在尝试使用以下命令创建项目:

rails mono_test_app -m http://gist.github.com/raw/284753/b5584c78fb5d29ab39a8218090801ea89b95a541/Rails%20MongoMapper%20Template

部分输出是

create  log/test.log
    applying  template: http://gist.github.com/raw/284753/b5584c78fb5d29ab39a8218090801ea89b95a541/Rails%20MongoMapper%20Template
   executing  rm public/index.html from /Users/olle/Projects/mono_test_app
   executing  rm public/images/rails.png from /Users/olle/Projects/mono_test_app
   executing  rm public/javascripts/controls.js from /Users/olle/Projects/mono_test_app
   executing  rm public/javascripts/dragdrop.js from /Users/olle/Projects/mono_test_app
   executing  rm public/javascripts/effects.js from /Users/olle/Projects/mono_test_app
   executing  rm public/javascripts/prototype.js from /Users/olle/Projects/mono_test_app
        file  app/views/layouts/application.html.erb
              What should I call the database? 
experiment
undefined method `env' for Rails:Module
Projects olle$ 

我使用-m参数指定的模板包含

# MongoDB FTW!
db_name = ask('What should I call the database? ')

initializer 'database.rb', <<-CODE
MongoMapper.database = "#{db_name}-#{Rails.env}"
CODE

file 'config/database.yml', <<-CODE
# Using MongoDB
CODE

github上的所有人似乎已经分叉或克隆了要点并且似乎使用它,为什么在我的系统上发生此错误?我错过了什么吗?

我已尝试过OSX和Ubuntu ruby 1.8.7(2008-08-11 patchlevel 72)[i686-darwin9.7.0] Rails 2.3.3

2 个答案:

答案 0 :(得分:3)

Rails.env是rails 3.0的做法。如果您不使用此版本,请改用RAILS_ENV

答案 1 :(得分:1)

我认为原因是使用了代码Rails.env中的某个位置。这是相当新的,我怀疑在rails 2.3.3中你能做到这一点。搜索该短语并将其替换为RAILS_ENV以查看是否有帮助。