Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - how do I avoid database altogether?

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).

like image 764
sa125 Avatar asked Oct 17 '10 17:10

sa125


People also ask

What is multiple DB support in rails 6?

With rails 6 multiple DB support, you can have more than one database with a replica (read-only copy) of each database. Now, consider your rails application with a single primary database, and now after upgrading to Rails 6, you need to add a new database for some of the new tables. The current version of your database.yml looks like:

How do I use multiple databases in rails?

Rails 6.0 ships with all the rails tasks you need to use multiple databases in Rails. You can run bin/rails -T to see all the commands you're able to run. You should see the following:

How does rails + active record work with multiple databases?

As a first-time multiple database user, my basic understanding of how Rails + Active Record manages the interactions with a single database went something like this: Rails gives us a database.yml file where we write some mysterious configurations. Active Record does the things (technical term) and magically connects the app to a database.

How to switch connections for one database in rails 6?

You can swap the role and the shard with the connected_to API. In Rails 6.1 it's possible to switch connections for one database instead of all databases globally. To use this feature you must first set config.active_record.legacy_connection_handling to false in your application configuration.


1 Answers

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 -= !)

like image 184
Zabba Avatar answered Sep 23 '22 16:09

Zabba