Created
February 1, 2009 08:45
-
-
Save cypok/55825 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rate < ActiveRecord::Base | |
belongs_to :user | |
belongs_to :book | |
validates_presence_of :user, :book, :value | |
validates_numericality_of :value, | |
:only_integer => true | |
validates_inclusion_of :value, | |
:in => 1..10, | |
:message => "should be from 1 to 10" | |
validate :uniqueness_of_user | |
def uniqueness_of_user | |
if user and book | |
errors.add_to_base :message => "You have already rated this book." if | |
Rate.count( :conditions => {:user_id => user.id, :book_id => book.id} ) != 0 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment