DataMapper的使用与现有的Rails应用程序 [英] Using Datamapper with existing rails application
问题描述
我有一个现有的Rails 3应用程序中使用的ActiveRecord,我想切换到的DataMapper。在DM-轨页给出的说明只说说创建一个新的应用程序。有谁知道如何扔掉所有的ActiveRecord依赖关系,并迁移到DataMapper的?
I have an existing Rails 3 application using ActiveRecord, and I want to switch to Datamapper. The instructions given in the dm-rails page only talk about creating a new application. Does anyone know how to throw away all activerecord dependancies and migrate to datamapper?
谢谢!
推荐答案
这是realtively简单,但也有几件事情你需要做的。
It's realtively straightforward, but there are a couple of things you need to do.
在你的Gemfile,删除轨道,而是需要把下面的。
In your Gemfile, remove "rails" and instead require the following.
gem 'activesupport', RAILS_VERSION, :require => 'active_support'
gem 'actionpack', RAILS_VERSION, :require => 'action_pack'
gem 'actionmailer', RAILS_VERSION, :require => 'action_mailer'
gem 'railties', RAILS_VERSION, :require => 'rails'
其中, RAILS_VERSION
是Rails的,你要使用的版本(例如〜> 3.1
)。这基本上是所有的轨道,除了ActiveRecord的。
Where RAILS_VERSION
is the version of Rails you want to use (e.g. ~> 3.1
). This is basically all of rails except ActiveRecord.
在配置/ application.rb中的顶部,去掉要求对轨(我忘了原来要求的样子),取而代之的是与特定的需要您需要的railties。
At the top of config/application.rb, remove the require for rails (I forget what the original require looks like) and replace it with specific requires for the railties you need.
require "action_controller/railtie"
require "action_mailer/railtie"
我想唯一的另一种是测试::单位railtie,但我们不使用测试::单位,所以我们不包括它。
I think the only other one is a Test::Unit railtie, but we're not using Test::Unit, so we don't include it.
最后,如果你想使用标识映射(我建议你做,但它并不需要),发生在你的ApplicationController的类主体:
Finally, if you want to use the identity map (I suggest you do, but it's not needed), place in your ApplicationController's class body:
use Rails::DataMapper::Middleware::IdentityMap
这应该是一切;根据README剩下的只是配置的database.yml(它的pretty的多交叉兼容标准轨了一艘)。
That should be everything; the rest is just configuring your database.yml according to the README (it's pretty much cross-compatible with a standard rails one anyway).
作为参考,看看什么样的发电机的作用:
For reference, take a look at what the generators does:
-zsh$ curl http://datamapper.org/templates/rails.rb
apply 'http://datamapper.org/templates/rails/gemfile.rb'
apply 'http://datamapper.org/templates/rails/application.rb'
如果你看一下这两个文件的内容,你会看到多余的东西,你会得到,如果你已经使用发电机。
If you look at the contents of those two files you'll see the extra stuff you'd get if you had used the generator.
这篇关于DataMapper的使用与现有的Rails应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!