Skip to content
Snippets Groups Projects
like.rb 639 B
Newer Older
# == Schema Information
#
# Table name: likes
#
#  id            :integer          not null, primary key
#  likeable_id   :integer
#  likeable_type :string
#  user_id       :integer
#  created_at    :datetime         not null
#  updated_at    :datetime         not null
#

Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
class Like < ApplicationRecord
  # *current_user* likes *likeable*
  # *current_user* unlikes *likeable*
  include Trackable

  belongs_to :likeable, polymorphic: true, counter_cache: true
  validates_presence_of :user, :likeable
  validates :user_id, uniqueness: { scope: [:likeable_id, :likeable_type] }