Rails 如何禁用ActiveRecord

有时候我们的rails应用并不需要操作数据库,一下子不知道怎么取消掉这个功能,最后在stackoverflow上找到了答案


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 yourconfig/application.rb

Removerequire 'rails/allline 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 yourdatabase.ymlfile,db/schema.rband migrations (if any)

4. Delete migration check intest/test_helper.rb

5. Delete any ActiveRecord configuration from yourconfig/environmentsfiles (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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容