我想在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
Run Code Online (Sandbox Code Playgroud)
我有一个错误
/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)
Run Code Online (Sandbox Code Playgroud) 现在Rails 3测试版已经发布了,我想我会重新编写一个我刚刚开始在Rails 3测试版上工作的应用程序,这两个版本都是为了感受它并获得一些启动.该应用程序使用MongoDB和MongoMapper的所有模型,因此不需要ActiveRecord.在以前的版本中,我按以下方式卸载activerecord:
config.frameworks -= [ :active_record ] # inside environment.rb
Run Code Online (Sandbox Code Playgroud)
在最新版本中,这不起作用 - 它只是抛出一个错误:
/Library/Ruby/Gems/1.8/gems/railties-3.0.0.beta/lib/rails/configuration.rb:126:in
`frameworks': config.frameworks in no longer supported. See the generated
config/boot.rb for steps on how to limit the frameworks that will be loaded
(RuntimeError)
from *snip*
Run Code Online (Sandbox Code Playgroud)
当然,我已经按照它的建议查看了boot.rb,但据我所知,这里没有任何关于如何卸载AR的线索.我需要这样做的原因是因为加载一些我不想要的东西不仅是愚蠢的,而且即使我试图为控制器运行一个生成器时它也无法建立数据库连接.这是因为我已经擦除database.yml并用MongoDB的连接细节替换它,以便使用这个要点将database.yml用于MongoDB连接细节.不知道为什么它需要能够启动数据库连接才能生成控制器....
有人知道正确的Rails 3方式吗?
我正在尝试使用rails 3而没有任何db后端,但是当我尝试访问某个页面时它仍然坚持要求'sqlite3'gem,并且抛出错误no such file to load -- sqlite3,即使应用程序中没有代码需要sqlite,除了我离开数据库.yml的默认设置为sqlite3,因为删除内容引发了其他错误.知道如何在没有任何数据库的情况下使用rails并避免出现错误吗?谢谢.
(另外,我对Sinatra很熟悉 - 只喜欢这个项目的rails).