rails and mongodb
I am trying out mongodb with Rails 3. after following instructions from mongomapper's site and a few others, i haven't been able to solve one small issue...
No value provided for required options '--orm'
I added a file mongo.rb in my config folder to make stuff tick
MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
MongoMapper.database = "cobboc_#{Rails.env}"
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
MongoMapper.connection开发者_JS百科.connect if forked
end
end
The mongo.rb file should be in config/initializers and contain:
require 'mongo_mapper' # loading mongo_mapper
MongoMapper.connection = Monog::Connection.new # localhost and port 27017 are the default values
MongoMapper.database = "cobboc_#{Rails.env}"
The Passenger extension is already done in the MongoMapper code.
If you'd like to use the database.yml file for configuration you can do:
require 'mongo_mapper'
db_config = YAML::load(File.read("#{Rails.root}/config/database.yml"))
if db_config[Rails.env] && db_config[Rails.env]['adapter'] == 'mongodb'
mongo_config = db_config[Rails.env]
MongoMapper.connection = Mongo::Connection.new(mongo_config['host'])
MongoMapper.database = mongo_config['database']
end
The project rails3-generators provides MongoMapper model generators to solve your issue. Require the gem in your Gemfile.
# Gemfile
gem 'rails3-generators'
Note, the Rails 3 generators have moved to the mongo_mapper gem
You didn't specify where you were getting the "orm" error
If it was in the "generate model" case you could call the following:
sudo gem install rails3-generators
rails generate model Book --skip-migration --orm=mongomapper
I was running:
$ rails generate scaffold project name:string
>> No value provided for required options '--orm'
Solution:
- Add rails3-generators to Gemfile
- $ rails g scaffold project name:string --skip-migration --orm=mongomapper
精彩评论