禁用 Rails 4 的 ActiveRecord [英] Disable ActiveRecord for Rails 4

查看:41
本文介绍了禁用 Rails 4 的 ActiveRecord的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Rails 4 中禁用 ActiveRecord.我在 config/application.rb

I want to disable ActiveRecord in Rails 4. I did the following in config/application.rb

require File.expand_path('../boot', __FILE__)

# require 'rails/all'  -- commented

require "action_controller/railtie"
require "action_mailer/railtie"
#require "active_resource/railtie" no need
#require "rails/test_unit/railtie" no need
#require "sprockets/railtie" no need

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module MyApp
  class Application < Rails::Application
     config.app_middleware.delete "ActiveRecord::ConnectionAdapters::ConnectionManagement"
  end
end

我有一个错误

/home/alex/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/railtie/configuration.rb:95:in 
  method_missing: undefined method active_record for #<Rails::Application::Configuration:0x00000002005c38> (NoMethodError)

推荐答案

如果你正在创建一个新的应用程序,你可以使用-O跳过ActiveRecord:

If you are creating a new application, you can use -O to skip ActiveRecord:

rails new my_app -O

对于现有应用程序:

1.从您的 Gemfile(mysql2、sqlite3 等)中删除数据库适配器 gem

2.更改您的 config/application.rb

删除 require 'rails/all 行并需要框架(其中包括 available 在您的rails 版本中,列表各不相同,不要只是复制)您想使用的,例如:>

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"

config/application.rb

3.删除您的 config/database.yml 文件、db/schema.rb 和迁移(如果有)

3. Delete your config/database.yml file, db/schema.rb and migrations (if any)

4.删除 test/test_helper.rb

5.从 config/environments 文件中删除任何 ActiveRecord 配置(这是导致错误的原因)

5. Delete any ActiveRecord configuration from your config/environments files (this is what is causing your error)

这就是你需要为一个空的 Rails 应用程序做的所有事情.如果您遇到由现有代码引起的问题,堆栈跟踪应该为您提供有关需要更改的内容的足够信息.例如,您的初始值设定项中可能有一些 ActiveRecord 配置.

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.

这篇关于禁用 Rails 4 的 ActiveRecord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆