MongoMapper and Rails 3-pre
Update: MongoMapper now works out of the box with Rails 3, thus the steps in this post are no longer needed. Happy hacking.
Although the usage of MongoMapper is straightforward, it takes some extra attention to get it running on an edgy Rails 3 (rails-3.0.pre) app. I followed three steps to get it working for me.
Keep in mind that these steps are needed right now as I write this post. I'm sure that all this will work out of the box when Rails 3 and MongoMapper are stable.
First off, remove ActiveRecord dependency from config/boot.rb file:
Otherwise you'll get an error saying that ActiveRecord cannot establish a connection.
Step 2. Point the MongoMapper gem source to its Github repository. This is done in the Gemfile:
Re-bundle:
$ gem bundle
Now you should be able to start up your app, but as soon as a model that includes MongoMapper::Document tries to set a callback, you'll get a nasty "undefined method before_foo" error. This happens as the MongoMapper Callbacks module is not yet compatible with the new ActiveModel API, which can be read about in a post by Yehuda Katz.
Last step. Your app should be running, but when a model is saved, you get a undefined method 'before save' kind of error. This happens as the callback module is not up-to-date with ActiveModel callbacks yet.
To get callbacks working, just drop-in-replace MongoMapper's callbacks.rb with (resides in vendor/gems/ruby..):
That's all. Nothing for production obviously, but sometimes we get impatient.
Comments [2]