Running Rails 3 with no ActiveRecord

I am just finishing a simple app that doesn’t require a database. When running it on the server I was getting errors saying :

LoadError (no such file to load — sqlite3):

But it was already commented out of my Gemfile. It took some thinking before I realized that ActiveRecord is probably looking for that by default regardless of whether or not I am including it in my Gemfile. So the solution was to remove ActiveRecord. That used to be reasonably obvious in Rails 2.3 but Rails 3 made it a little less so. A standard config.application.rb file starts with the lines:

require File.expand_path(‘../boot’, __FILE__)

require ‘rails/all’

Rails 3 is broken up into a bunch of different parts and that require ‘rails/all’ pulls in, well all of them including ActiveRecord. An equivalent statement would be:

require “active_record/railtie”
require “action_controller/railtie”
require “action_mailer/railtie”
require “active_resource/railtie”
require “rails/test_unit/railtie”

Of course once you have exchanged ‘rails/all’ for that, you can simply comment out ActiveRecord and that’s that. If you are starting a new Rails app you can have Rails do that for you by using the flags -O or –skip-activerecord.

Now that AR is gone, my app starts without looking for a database and all is goodness and light.


One thought on “Running Rails 3 with no ActiveRecord”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s