Making a Rails App Without a Database or ActiveRecord
Occasionally, you may want to build a Rails app without ActiveRecord or a database. Your application might only store data using third party APIs, or might not have any persistent data at all. Since Rails optimizes for the most common case (a database-backed app), it refuses to start the server without a database connection by default.
Luckily, it only takes three steps to make Rails work without a database:
- Remove any database gems (sqlite, pg, mysql, etc) from your Gemfile and then run bundle.
- Change your application.rb. The default app generated by Rails 4.0 requires all of Rails:
This includes ActiveRecord, which requires a database connection. Instead, you must include the specific parts of Rails that you will be using, for example:
require 'action_controller/railtie' require 'action_mailer/railtie' require 'active_model/railtie' require 'sprockets/railtie' require 'rails/test_unit/railtie'
- Remove any references to active_record in your configuration. The default app generated by Rails 4.0 has one reference to active record which must be removed, in config/environments/development.rb:
config.active_record.migration_error = :page_load
With these changes, I was able to get the Rails application started up without a database connection. I also verified that these steps allow the app to be deployed to heroku without a database add-on.