Now that Rails 3 beta is out, I thought I’d have a look at rewriting an app I have just started work on in Rails 3 beta, both to get a feel for it and get a bit of a head-start. The app uses MongoDB and MongoMapper for all of its models and therefore has no need for ActiveRecord. In the previous version, I am unloading activerecord in the following way:
config.frameworks -= [ :active_record ] # inside environment.rb
In the latest version this does not work – it just throws an error:
/Library/Ruby/Gems/1.8/gems/railties-3.0.0.beta/lib/rails/configuration.rb:126:in
`frameworks': config.frameworks in no longer supported. See the generated
config/boot.rb for steps on how to limit the frameworks that will be loaded
(RuntimeError)
from *snip*
Of course, I have looked at the boot.rb as it suggested, but as far as I can see, there is no clue here as to how I might go about unloading AR. The reason I need to do this is because not only is it silly to be loading something I don’t want, but it is complaining about its inability to make a DB connection even when I try to run a generator for a controller. This is because I’ve wiped database.yml and replaced it with connection details for MongoDB in order to use this gist for using database.yml for MongoDB connection details. Not sure why it needs to be able to initiate a DB connection at all just to generate a controller anyway….
Is anyone aware of the correct Rails 3 way of doing this?
I’m going by this from reading the source, so let me know if it actually worked. 🙂
The
railscommand that generates the application template now has an option-O, which tells it to skip ActiveRecord.If you don’t feel like rerunning
rails, you should check the following in your existing app:Check that your
config/application.rbdoesn’t haverequire 'rails/all'orrequire "active_record/railtie". Instead, for a standard Rails setup without ActiveRecord, it should have only the following requires:If, in
config/application.rb, you are using theconfig.generatorssection, make sure it doesn’t have the lineg.orm :active_record. You can set this explicitly tonil, if you want, but this should be the default wheng.ormis completely omitted.Optional, but in your
Gemfile, remove thegemline that loads the module for your database. This could be the linegem "mysql"for example.