markdown 禁用ActiveRecord for Rails 4,5

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 禁用ActiveRecord for Rails 4,5相关的知识,希望对你有一定的参考价值。

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 you want to use, for example:

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

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.




Since this is still the first hit when searching Google for disabling active record for Rails 5, I'll add this here:

For Rails 5

Do all the steps in @mechanicalfish answer, but also remove the line

Rails.application.config.active_record.belongs_to_required_by_default = true

from

config/initializers/new_framework_defaults.rb

以上是关于markdown 禁用ActiveRecord for Rails 4,5的主要内容,如果未能解决你的问题,请参考以下文章

如何禁用某个列的 ActiveRecord 日志记录?

markdown 禁用ActiveRecord for Rails 4,5

获取 ActiveRecord 中每个组的最小值/最大值

ActiveRecord:包括组中的关联

使用 Activerecord、Rails 和 Postgres 查找具有多个重复字段的行

如何使用 ActiveRecord json 字段类型