# active_record is what we're not going to use it, so add it comment in case
# at some point you enable it back again
# require "active_record/railtie"
# This is not loaded in rails/all but inside active_record so add it if
# you want your models work as expected
require "active_model/railtie"
# And now the rest
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "active_job/railtie" # Only for Rails >= 4.2
require "action_cable/engine" # Only for Rails >= 5.0
require "sprockets/railtie" # Deprecated for Rails >= 7, so add it only if you're using it
require "rails/test_unit/railtie"
# All these depend on active_record, so they should be excluded also
# require "action_text/engine" # Only for Rails >= 6.0
# require "action_mailbox/engine" # Only for Rails >= 6.0
# require "active_storage/engine" # Only for Rails >= 5.2
请留意注解,了解关于您的Rails版本要加载哪些内容。 还要检查以下文件(如果有)并注解以下行:
# package.json
"@rails/activestorage": "^6.0.0",
# app/javascript/packs/application.js
require("@rails/activestorage").start()
# bin/setup
system! 'bin/rails db:prepare'
# config/environments/development.rb
config.active_storage.service = :local # For Rails >= 5.2
config.active_record.migration_error = :page_load
config.active_record.verbose_query_logs = true
# config/environments/test.rb
config.active_storage.service = :test # For Rails >= 5.2
# config/environments/production.rb
config.active_storage.service = :local # For Rails >= 5.2
config.active_record.dump_schema_after_migration = false
# spec/rails_helper.rb
ActiveRecord::Migration.maintain_test_schema!
# test/test_helper.rb
fixtures :all # In case you're using fixtures
# Only for Rails >= 5.0
#config/initializers/new_framework_defaults.rb
Rails.application.config.active_record.belongs_to_required_by_default = true
module ActiveRecord
module ConnectionAdapters
class NullDBAdapter < ActiveRecord::ConnectionAdapters::AbstractAdapter
def new_table_definition(table_name = nil, is_temporary = nil)
TableDefinition.new(table_name, is_temporary)
end
end
end
end
6条答案
按热度按时间gupuwyp21#
对于导轨3和导轨4:
使用
-O
(大写“O”)或--skip-activerecord
选项生成不带数据库的应用程序。rails new myApp -O
或
rails new myApp --skip-activerecord
此答案从此处重新共享
对于导轨5:
使用
--skip-active-record
选项生成不带数据库的应用程序请注意与之前的Rails版本相反的额外连字符“-”。
rails new myApp --skip-active-record
jyztefdp2#
对于新项目,使用简单的
rails new your_app --skip-active-record
就可以了,但是对于现有的Rails 4-7项目,在config/application.rb
文件中有以下行:(As参考线路正在加载this file)
因此,您必须按如下方式分别加载每个库,而不是加载ALL:
请留意注解,了解关于您的Rails版本要加载哪些内容。
还要检查以下文件(如果有)并注解以下行:
还要删除模型文件中对
ActiveRecord::Base
的任何引用(如果适用,也可以直接删除这些文件),例如,自动生成的app/models/application_record.rb
文件。hujrc8aj3#
取消注解
environment.rb
文件中的此行:sh7euo9m4#
在Rails 4中,启动新项目时,可以使用-O或--skip-active-record
如果您已经创建了一个项目,则需要添加注解
从配置/应用程序.rb和
来自配置/环境/开发.rb
ie3xauqp5#
如果你不需要数据库,那么你可能不需要大量的Rails,你可能需要一个更小的、更可定制的框架。
Sinatra是一个非常小的框架,非常适合提供基本的静态页面。
但是如果您坚持使用Rails,那么有一篇文章将向您展示如何使用Rails here或here。
odopli946#
为了支持Rails 6 rc 1和
activerecord-nulldb-adapter
gem,我们需要一个猴子补丁在配置/初始化程序/null_db_adapter_monkey_patches.rb中