class Address < ActiveRecord::Base belongs_to :addressable, polymorphic: true end
My Second Model: app/models/user.rb class User < ActiveRecord::Base has_many :addresses, as: :addressable end My third model: app/models/company.rb class Company < ActiveRecord::Base has_many :addresses, as: :addressable end For Address table, I have this migration: class CreateAddresses < ActiveRecord::Migration def change create_table :addresses do |t| t.string :description t.references :addressable, polymorphic: true t.timestamps end end end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5eb515f9f606ff97fca7967dc3b96e66%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.