Rails 3.*: Moving to MongoDB
This happens to me all the time. You start a new rails application, you want to use MongoDB but you forgot to include --skip-active-record
when you ran rails new
.
Or maybe you have an existing applications and want to move from SQL to MongoDB.
Here are all the changes necessary to restore order and allow you to go forward with using mongoid/mongomapper/whatever.
# config/application.rb:
- require 'rails/all'
+ require "action_controller/railtie"
+ require "action_mailer/railtie"
+ require "active_resource/railtie"
+ require "rails/test_unit/railtie"
+ require "sprockets/railtie" # Only required if you're using asset pipeline
# Only in Rails 3.2.3+
- config.active_record.whitelist_attributes = true
# config/environments/development.rb
- config.active_record.mass_assignment_sanitizer = :strict
- config.active_record.auto_explain_threshold_in_seconds = 0.5
# config/environments/test.rb
- config.active_record.mass_assignment_sanitizer = :strict
Written by Ian Bishop
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#