You don't need to remove the activerecord
gem to switch ORM's to Mongoid. Which is actually not possible since its a dependency of Rails.
To remove ActiveRecord from the application:
1. Get rid of the railtie.
Railties are how you load parts of the framework in rails.
# config/application.rb
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie" -- remove or comment this line!
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
This means that the active_record
gem will no longer be required and loaded into memory.
2. Clean up the configuration
When you generate a new rails app your config has quite a few ActiveRecord specific options. So use grep
or the search option in your favorite editor to remove any lines containing and remove all lines containing config.active_record
from config/environments/*.yml
.
3. Remove cruft
You can then get rid of the following files/folders:
/config/database.yml
/db/schema.rb
/db/migrate
Update - This is a small project what if someone have to switch from
active record to mongoid in a live and big project. How will a person
can migrate in such a scenario?
Switching ORMs in a mature project is pretty rare as it will require extensive rebuilding. But you would follow the steps above or run Mongoid and ActiveRecord in parallel until the conversion is complete. This is hardly something you would do live - it is most like a long running major version project.