Skip to content

Instantly share code, notes, and snippets.

@Chryus
Last active February 16, 2017 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chryus/c1e258af03626648b242a375892c60a8 to your computer and use it in GitHub Desktop.
Save Chryus/c1e258af03626648b242a375892c60a8 to your computer and use it in GitHub Desktop.
# graffiti.rb
class Graffiti < ActiveRecord::Base
has_many :uploads
has_many :upvotes, as: :upvotable
end
# upload.rb
class Upload < ApplicationRecord
belongs_to :user
belongs_to :graffiti
has_many :upvotes, as: :upvotable
end
# upvote.rb
class Upvote < ApplicationRecord
belongs_to :user
belongs_to :upvotable, polymorphic: true
end
# schema
create_table :upvotes do |t|
t.integer :user_id
t.integer :upvotable_id
t.string :upvotable_type
t.timestamps
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment