I am new to association.any one explain me where to use polymorphic association and its
purpose .
class Picture < ActiveRecord::Base
belongs_to :imageable, :polymorphic => true
end
class Employee < ActiveRecord::Base
has_many :pictures, :as => :imageable
end
class Product < ActiveRecord::Base
has_many :pictures, :as => :imageable
end
Thanks in advance.
polymorphic association is used when the parent or child object class is not known.
eg
here, C may either belong to A or B.
see http://guides.rubyonrails.org/association_basics.html#polymorphic-associations for more information.