Skip to content

Instantly share code, notes, and snippets.

@SteveOscar
Created December 30, 2015 18:06
Show Gist options
  • Save SteveOscar/7cddc7eca7a48ccd04f5 to your computer and use it in GitHub Desktop.
Save SteveOscar/7cddc7eca7a48ccd04f5 to your computer and use it in GitHub Desktop.
Basic Polymorphic Association
class Tag < ActiveRecord::Base
belongs_to :taggable, polymorphic: true
end
class Article < ActiveRecord::Base
has_many :tags, as: :taggable
end
class Newspaper < ActiveRecord::Base
has_many :tags, as: :taggable
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment