Disable ActiveRecord for Rails 4
If you are creating a new application, you can use -O
to skip ActiveRecord:
rails new my_app -O
For existing applications:
1. Remove database adapter gems from your Gemfile (mysql2, sqlite3, etc.)
2. Change your config/application.rb
Remove require 'rails/all
line and require frameworks (among those available in your rails
version, the list varies, do not just copy) you want to use, for example:
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
Remove config.active_record.raise_in_transactional_callbacks = true
from config/application.rb
3. Delete your config/database.yml
file, db/schema.rb
and migrations (if any)
4. Delete migration check in test/test_helper.rb
5. Delete any ActiveRecord configuration from your config/environments
files (this is what is causing your error)
This is all you need to do for an empty Rails app. If you run into problems caused by your existing code, stack trace should give you sufficient information on what you need to change. You might for example have some ActiveRecord configuration in your initializers.
How do I remove ActiveRecord from an existing Rails 4 Application?
Follow these steps
Remove database adapter gems from your Gemfile, e.g., mysql2, sqlite3, etc
From
application.rb
, removerequire 'rails/all'
and require frameworks (among those available in yourrails
version, the list varies, do not just copy) you want to use, for example:require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"Delete
database.yml
,schema.rb
and all the migrations- Delete migration checks from
test/test_helper.rb
- Delete all activerecord related configuration from
config/environments
Hope this helps!
Source - Disable ActiveRecord for Rails 4
Disable ActiveRecord in Ruby on Rails 5
Accepted answer in this post of mechanicalfish is right.
But in my case, I've done following 2 additional things (I've used Rails 5.1.2)
Delete model files in models directory
models/application_record.rb
models/widget.rb
Hope this helps!
How to skip active record for existing project in Rails 6
To replicate the skip-active-record
setup in an existing project, follow the steps in this answer
PLUS
REMOVE config/environments/development.rb -> config.active_storage.service = :local
REMOVE config/environments/production.rb -> config.active_storage.service = :local
REMOVE config/environments/test.rb -> config.active_storage.service = :local
REMOVE bin/setup -> puts "\n== Preparing database =="
system! 'bin/rails db:prepare'
DELETE config/storage.yml
REMOVE test/test_helper.rb # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
Disable ActiveRecord lazy loading for debugging?
ActiveRecord's querying API revolves around the concept of lazy loading. When I go in to try to clean up N+1 queries I find myself constantly fighting against the way AR was designed to work, which makes it sooo tempting to say "Meh, computers are fast enough".
This is one of several usability reasons that I've decided to switch to Elixir / Phoenix for all future development work; the Ecto ORM makes it literally impossible to lazy load data; you either load an association at query evaluation time or you don't have the associated data, you need to explicitly query it later on.
One very partial suggestion: Install the Bullet gem and use its Bullet.raise = true
setting to crash the app if you see any lazy loading. Troubleshooting with Bullet is awkward because it's fighting against ActiveRecord's natural behavior, so it can only tell you where the N+1 query was lazily triggered, not where in the code the query was originally composed (and where you might need to add includes
). But at least with this gem in place you can get part of the information you're seeking:
- Is this code executing obvious N+1 queries?
- Where in the code was the N+1 query triggered?
- What class and association name is the culprit?
Disable ActiveRecord parameter filtering
By default, when you create a new Rails app this template will be used to create an initializer called config/initializers/filter_parameter_logging.rb
. You can edit the Rails.application.config.filter_parameters
values that are configured in this file. You'll need to restart the app after making changes.
Rather than just remove :token
from the list, you might want to change that to :authenticity_token
so that you still filter out the Rails authenticity token.
Related Topics
How to Check If a Value Exists in an Array in Ruby
How to Understand Nil Vs. Empty Vs. Blank in Ruby
Look Up All Descendants of a Class in Ruby
Your Ruby Version Is 2.0.0, But Your Gemfile Specified 2.1.0
Ruby Function to Remove All White Spaces
Best Way to Escape and Unescape Strings in Ruby
How to Use Ruby/Rails Variables Inside Sass
What's the Best Way to Model Recurring Events in a Calendar Application
To_D to Always Return 2 Decimals Places in Ruby
Difference Between "Or" and || in Ruby
How to Test If a String Is Basically an Integer in Quotes Using Ruby
What Does the "===" Operator Do in Ruby
Why How to Refer to a Variable Outside of an If/Unless/Case Statement That Never Ran
How to Make a Http Request Using Ruby on Rails