Rails polymorphic的使用和理解

阅读更多
class Person < ActiveRecord::Base
  has_one :address, :as => :addressable
end

class Company < ActiveRecord::Base
  has_one :address, :as => :addressable
end

class Address < ActiveRecord::Base
 belongs_to :addressable, :polymorphic => true
end


Address 有adressable_id addressable_type其中,addressable_type可以为Company或者Person

你可能感兴趣的:(rails,ruby,polymophic)