当前位置:  开发笔记 > 编程语言 > 正文

rails生成不使用mongoid

如何解决《rails生成不使用mongoid》经验,为你挑选了1个好方法。

我刚刚在带有mongoid的rails中创建了一个app.

当我尝试按照mongoid网站上的教程运行时

rails g mongoid:config

我得到以下一组错误.

/Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/whiny_nil.rb:48:in `method_missing': undefined method `values' for nil:NilClass (NoMethodError)
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.3.4/lib/mongoid/railtie.rb:64:in `block in '
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `run'
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `each'
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/application.rb:96:in `initialize!'
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/XXXXXX/melodizr/config/environment.rb:5:in `'
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/application.rb:83:in `require'
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/application.rb:83:in `require_environment!'
from /Users/XXXXXX/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.1/lib/rails/commands.rb:22:in `'
from script/rails:6:in `require'
from script/rails:6:in `
'

请帮助,这是杀了我,我觉得我没有错过任何东西,但它迟到了,我可能错了.



1> Tyler Brock..:

你在运行什么版本的rails?

有些东西搞砸了.确保您拥有最新的gem(不要在gemfile中指定版本):

在rails app dir中运行所有这些:

gem update --system
gem update
bundle install
bundle update

现在你已经掌握了最新动态.如果它stil barfs,只需自己制作文件.这个生成器所做的就是在config目录中创建mongoid.yml,如下所示:

development:
  host: localhost
  database: mongoid_test_development

test:
  host: localhost
  database: mongoid_test_test

# set these environment variables on your prod server
production:
  host: <%= ENV['MONGOID_HOST'] %>
  port: <%= ENV['MONGOID_PORT'] %>
  username: <%= ENV['MONGOID_USERNAME'] %>
  password: <%= ENV['MONGOID_PASSWORD'] %>
  database: <%= ENV['MONGOID_DATABASE'] %>
  # slaves:
  #   - host: slave1.local
  #     port: 27018
  #   - host: slave2.local
  #     port: 27019

推荐阅读
黄晓敏3023
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有