rails and mongodb

1.5k views Asked by At

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.connect if forked
  end
end
4

There are 4 answers

0
Kevin Faustino On BEST ANSWER

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

1
Stefaan Colman On

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
0
Anil On

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

0
carl crott On

I was running:

$ rails generate scaffold project name:string

>> No value provided for required options '--orm'

Solution:

  1. Add rails3-generators to Gemfile
  2. $ rails g scaffold project name:string --skip-migration --orm=mongomapper