猿问

禁用ActiveRecord for Rails 4

我想在Rails 4中禁用ActiveRecord。在 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)


哔哔one
浏览 600回答 3
3回答

蛊毒传说

嗨,这是默认的新new_app -O给出的结果require "rails"# Pick the frameworks you want:&nbsp;require "active_model/railtie"&nbsp;require "active_job/railtie"# require "active_record/railtie"&nbsp;require "action_controller/railtie"&nbsp;require "action_mailer/railtie"&nbsp;require "action_view/railtie"&nbsp;require "sprockets/railtie"&nbsp;require "rails/test_unit/railtie"在您的config / application.rb中此外,它没有database.yml,也没有db / migrate / *和schema.rb

慕妹3146593

由于这仍然是搜索Google以禁用Rails 5的活动记录时的第一击,因此,请在此处添加以下内容:对于Rails 5执行@mechanicalfish答案中的所有步骤,但也删除该行Rails.application.config.active_record.belongs_to_required_by_default = true从config/initializers/new_framework_defaults.rb
随时随地看视频慕课网APP

相关分类

Ruby
我要回答