Skip to content

Instantly share code, notes, and snippets.

@noahd1
Created September 25, 2012 03:17
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 noahd1/3779794 to your computer and use it in GitHub Desktop.
Save noahd1/3779794 to your computer and use it in GitHub Desktop.
Example of using also_validates for racquet.io
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