Skip to content
Snippets Groups Projects
bookmark.rb 693 B
Newer Older
# == Schema Information
#
# Table name: bookmarks
#
#  id                :integer          not null, primary key
#  user_id           :integer
#  bookmarkable_id   :integer
#  bookmarkable_type :string
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#

Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
class Bookmark < ApplicationRecord
  # Example of Trackable:
  # *current_user* create bookmark *bookmarkable*
  include Trackable

  belongs_to :user, counter_cache: true
  belongs_to :bookmarkable, polymorphic: true

  validates_presence_of :user, :bookmarkable
  validates :user_id, uniqueness: { scope: [:bookmarkable_id, :bookmarkable_type] }