refactoring - Ruby on Rails: Possible/preferrable to implement single table inheritance after creating separate models? -
i've built simple address book application in intro ruby on rails class separate models street addresses (address), email addresses (email), , web addresses (web) using nested forms using single controller (entry). i'd change last 2 models (email , web) use single table inheritance base url table. preferable (or possible) compared rebuilding app scratch correct inheritance relationships?
i've included existing models below:
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 how changing
class email < activerecord::base and
class web < activerecord::base to
class email < url and
class web < url affect existing application?
thanks in advance , advice.
be sure add url class that's inheriting activerecord::base class.
class url < activerecord::base belongs_to :entry belongs_to :address_type attr_accessible :address_type_id :entry_id end class email < url attr_accessible :email validates_email_format_of :email end class web < url attr_accessible :web end also add line entry.rb:
has_many :urls, dependent: :destroy
Comments
Post a Comment