Rails 3 - 如何完全避免使用数据库? [英] Rails 3 - how do I avoid database altogether?
问题描述
我正在尝试在没有任何数据库后端的情况下使用 rails 3,但是当我尝试访问页面时它仍然坚持要求使用 'sqlite3' gem,并抛出错误 no such file to load -- sqlite3
,即使应用程序中没有任何代码需要 sqlite,但我将 database.yml 保留为 sqlite3 的默认设置,因为删除内容会引发其他错误.知道如何在没有任何数据库的情况下使用 rails 并避免上述错误吗?谢谢.
I'm trying to use rails 3 without any db backend, but it still insists on requiring 'sqlite3' gem when I try to access a page, and throws an error no such file to load -- sqlite3
, even though no code in the application requires sqlite, except I left database.yml with its default setting for sqlite3, since removing the content raised other errors. Any idea how I could use rails without any database and avoid said errors? thanks.
(另外,我对 Sinatra 很熟悉——只是更喜欢这个项目的 rails).
(also, I'm familiar with Sinatra - just prefer rails for this project).
推荐答案
Rails 3:
在 application.rb
中,删除 require 'rails/all'
行并添加以下行:
In application.rb
, remove the require 'rails/all'
line and instead add these lines:
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"
另请参阅在 Rails 3 中删除 ActiveRecord并查看 Active Model railscast
Also see Remove ActiveRecord in Rails 3 and look into the Active Model railscast
Rails 3.2.x:
Rails 3.2.x:
您还需要在 application.rb 中删除/注释掉这一行
You'll also need to remove/comment out this line in application.rb
config.active_record.whitelist_attributes = true
并从 development.rb 中删除/注释这两行
And remove/comment these two lines from development.rb
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
Rails 2.x:
在 config/environment.rb
中添加(或取消注释)该行
In config/environment.rb
add (or uncomment) the line
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
这将导致 Rails 不使用这些框架.(注意几乎不可见的 -=
!)
This will cause Rails not to use those frameworks. (Note the nearly-invisible -=
!)
这篇关于Rails 3 - 如何完全避免使用数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!