Mongoid and ActiveRecord generators

2019-03-28 12:18发布

问题:

I have both ActiveRecord (MySQL) and Mongoid in my Rails 3.1 application. Everything is fine, excepts all generators uses mongoid to generate models. This way, when i:

rails g model user

i receive mongoid-like model, but i need ActiveRecord structure and migrations.

How can i switch back to AR?

回答1:

Mongoid overrides the model generator, but you can switch it back.

In config/application.rb you can either add a line if you've already got a block similar to this:

config.generators do |g|
  g.template_engine :haml
  ...
  g.orm :active_record
end

Or just simply add the entire config line directly to the file

config.generators.orm :active_record

You can also pass :migrations => false if you want to turn off migrations