Skip to content

Instantly share code, notes, and snippets.

@stevecass
Created April 20, 2016 15:30
Show Gist options
  • Save stevecass/114c8e498393fceaeb31f21eb0e95982 to your computer and use it in GitHub Desktop.
Save stevecass/114c8e498393fceaeb31f21eb0e95982 to your computer and use it in GitHub Desktop.
class Post < ActiveRecord::Base
has_many :comments, as: :commentable
end
class Photo < ActiveRecord::Base
has_many :comments, as: :commentable
end
class Comment < ActiveRecord::Base
belongs_to :commentable, polymorphic: true
end
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.integer :user_id, index: true
t.string :title
t.text :body
t.string :publication_status
t.date :published_on
end
create_table :photos do |t|
t.integer :post_id, index: true
t.string :caption
end
create_table :comments do |t|
t.references :commentable, polymorphic: true, index: true
t.integer :user_id, index: true
t.string :body
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment