I've built a simple address book application in my intro Ruby on Rails class with separate models for street addresses (Address), email addresses (Email), and web addresses (Web) using nested forms using a single controller (Entry). I'd like to now change the last two models (Email and Web) to use single table inheritance from a base Url table. Is that preferable (or even possible) compared to rebuilding the app from scratch with the correct inheritance relationships?
I've included my 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 would changing
class Email < ActiveRecord::Base
and
class Web < ActiveRecord::Base
to
class Email < Url
and
class Web < Url
affect my existing application?
Thanks in advance for your help and advice.