Skip to content

Instantly share code, notes, and snippets.

@rvanlieshout
Created March 14, 2011 14:30
Show Gist options
  • Save rvanlieshout/869208 to your computer and use it in GitHub Desktop.
Save rvanlieshout/869208 to your computer and use it in GitHub Desktop.
class Registration < ActiveRecord::Base
# Database Relationships
belongs_to :person
belongs_to :event
# Validations
validates_presence_of :event_id
validates_presence_of :person_id
validates_uniqueness_of :person_id, :scope => :event_id, :message => "is already signed in or registered."
validate do |registration|
registration.errors.add(:event, :passed) if registration.event && registration.event.finish < Time.now
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment