45

I'm trying to use rails 3 without any db backend, but it still insists on requiring 'sqlite3' gem when I try to access a page, and throws an error no such file to load -- sqlite3, even though no code in the application requires sqlite, except I left database.yml with its default setting for sqlite3, since removing the content raised other errors. Any idea how I could use rails without any database and avoid said errors? thanks.

(also, I'm familiar with Sinatra - just prefer rails for this project).

Florin
  • 1,844
  • 2
  • 16
  • 21
sa125
  • 28,121
  • 38
  • 111
  • 153

2 Answers2

98

Rails 3:

In application.rb, remove the require 'rails/all' line and instead add these lines:

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"

Also see Remove ActiveRecord in Rails 3 and look into the Active Model railscast

Rails 3.2.x:

You'll also need to remove/comment out this line in application.rb

config.active_record.whitelist_attributes = true

And remove/comment these two lines from development.rb

config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5

Rails 2.x:

In config/environment.rb add (or uncomment) the line

config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

This will cause Rails not to use those frameworks. (Note the nearly-invisible -= !)

Community
  • 1
  • 1
Zabba
  • 64,285
  • 47
  • 179
  • 207
  • I think this works in rails 2.x - I get a deprecation message and an error in r3. – sa125 Oct 17 '10 at 17:29
  • Updated the answer with the method used in Rails 3 – Zabba Oct 17 '10 at 17:53
  • 2
    In Rails 3.1 and 3.2 you need to also follow the advice in Rod's answer, which is to remove all references to `config.activerecord` in the config/environments files. – Mark Thomas Mar 12 '12 at 17:15
  • In the end I didn't need the `config.frameworks -= [ :active_record, :active_resource, :action_mailer ]`. I'm on 3.2.13, and it seemed to work out just fine if I did the rest of these changes and Rod's as well. Thanks! – Lucy Bain May 22 '13 at 03:41
10

Also, in Rails 3, remove any references to active_record in

config/environments/development.rb

config/environments/test.rb and

config/environments/production.rb such as

config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5

as well as removing require "rails/all" and adding the require lines in comment 21 (above).

if you are not using a database (this works with Rails 3.1.1)

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
Rod McLaughlin
  • 101
  • 1
  • 2