【发布时间】:2013-05-24 05:01:11
【问题描述】:
我在我的 Ruby on Rails 简介类中构建了一个简单的地址簿应用程序,它使用单个控制器(条目)使用嵌套表单为街道地址(地址)、电子邮件地址(电子邮件)和网址(Web)提供了单独的模型)。我现在想更改最后两个模型(电子邮件和 Web)以使用来自基本 Url 表的单表继承。与使用正确的继承关系从头开始重建应用程序相比,这是否更可取(甚至可能)?
我在下面包含了我现有的模型:
class Entry < ActiveRecord::Base
attr_accessible :first_name, :last_name, :addresses_attributes, :webs_attributes, :emails_attributes
has_many :addresses, dependent: :destroy
has_many :emails, dependent: :destroy
has_many :webs, dependent: :destroy
accepts_nested_attributes_for :addresses, :emails, :webs, allow_destroy: true, reject_if: :all_blank
end
class Address < ActiveRecord::Base
belongs_to :entry
belongs_to :address_type
attr_accessible :address_type_id, :city, :state, :street, :zip
end
class Email < ActiveRecord::Base
belongs_to :entry
belongs_to :address_type
attr_accessible :address_type_id, :email, :entry_id
validates_email_format_of :email
end
class Web < ActiveRecord::Base
belongs_to :entry
belongs_to :address_type
attr_accessible :address_type_id, :web, :entry_id
end
如何改变
class Email < ActiveRecord::Base
和
class Web < ActiveRecord::Base
到
class Email < Url
和
class Web < Url
影响我现有的应用程序?
提前感谢您的帮助和建议。
【问题讨论】:
标签: ruby-on-rails refactoring single-table-inheritance