本文介绍了在 rails 3 中使用 --skip-active-record 选项创建项目后恢复 AR 支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有上述选项的 Rails 3 项目.我可以以某种方式还原"此选项并将活动记录恢复为默认值,还是必须创建一个新项目?

I have created a Rails 3 project with mentioned option. Can I somehow "revert" this option and have active record back as in default, or must I create a new project?

编辑

好的,要获得 ActiveRecord 支持,我必须:

Ok, to have ActiveRecord support back I had to:

  1. 删除 application.rb 中单独的 require 调用并将其替换为 require 'rails/all'(或者只是取消注释 # require "active_record/railtie")
  2. 取消注释 # gem 'sqlite3-ruby', :require =>Gemfile 中的 'sqlite3' 行(用于 sqlite)
  3. 创建 database.yml 文件并用选项填充它
  4. 调用rake db:create任务
  1. Delete separate require calls in application.rb and replace it with require 'rails/all' (or just uncomment # require "active_record/railtie")
  2. Uncomment # gem 'sqlite3-ruby', :require => 'sqlite3' line in Gemfile (for sqlite)
  3. Create database.yml file and fill it with options
  4. invoke rake db:create task

在那之后,我似乎可以像往常一样继续使用 AR.

After that it seems that I can continue to work with AR as usual.

推荐答案

用 ActiveRecord 创建一个新项目,然后成对 diff config/application.rbconfig/environments/*.rb 以确定是否有任何默认设置您应该添加回您的项目.

Make a new project with ActiveRecord, and then pairwise diff config/application.rb and config/environments/*.rb to determine if there are any default settings you should add back to your project.

这篇关于在 rails 3 中使用 --skip-active-record 选项创建项目后恢复 AR 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 10:21