Skip to content
Snippets Groups Projects
follow.rb 594 B
Newer Older
# == Schema Information
#
# Table name: follows
#
#  id              :integer          not null, primary key
#  followable_id   :integer
#  followable_type :string
#  user_id         :integer
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#

class Follow < ActiveRecord::Base
  # *current_user* follows *followable*
  include Trackable

  belongs_to :followable, polymorphic: true, counter_cache: true
  belongs_to :user
  validates_presence_of :user, :followable
  validates :user_id, uniqueness: { scope: [:followable_id, :followable_type] }