# == 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 # 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] } def recipient bookmarkable end end