Skip to content

Instantly share code, notes, and snippets.

@pcg79
Created July 9, 2011 12:22
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 pcg79/1073556 to your computer and use it in GitHub Desktop.
Save pcg79/1073556 to your computer and use it in GitHub Desktop.
class Rating < ActiveRecord::Base
belongs_to :user
belongs_to :rater, :class_name => 'User', :foreign_key => 'rater_id'
belongs_to :account
attr_accessible :score, :rater_id, :user_id, :rater, :user
VALID_SCORES = 1..3
validates_presence_of :score, :user_id, :rater_id, :account_id
validates_inclusion_of :score, :in => VALID_SCORES, :message => "must be 1, 2, or 3"
validates_uniqueness_of :user_id, :scope => :rater_id, :message => 'has already been rated'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment