Created
September 25, 2012 03:17
-
-
Save noahd1/3779794 to your computer and use it in GitHub Desktop.
Example of using also_validates for racquet.io
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 MatchEntry | |
include Informal::Model | |
attr_accessor :winner_registration, :loser_registration | |
validate :different_twitter_handles? | |
also_validates :winner_registration, :loser_registration | |
def initialize(options = {}) | |
@winner_registration = options[:winner_registration] | |
@loser_registration = options[:loser_registration] | |
@club = options[:club] | |
end | |
def save_match | |
return false unless valid? | |
@club.matches.create(winner: @winner_registration.member, loser: @loser_registration.member) | |
end | |
private | |
def different_twitter_handles? | |
if @winner_registration.twitter_handle == @loser_registration.twitter_handle | |
errors.add(:base, "Winner and loser must be different players") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment