Skip to content

Instantly share code, notes, and snippets.

@dansteen
Created January 19, 2011 03:30
Show Gist options
  • Save dansteen/785638 to your computer and use it in GitHub Desktop.
Save dansteen/785638 to your computer and use it in GitHub Desktop.
class Call < ActiveRecord::Base
before_destroy :check_associations
before_validation :normalize_state
before_save :normalize_times
belongs_to :clear_unit, :class_name=>"Member"
belongs_to :call_dispatcher
belongs_to :call_category
has_many :patients, :dependent => :restrict
has_many :responses, :dependent => :destroy, :order => 'arrival ASC'
has_many :recordings, :dependent => :destroy
has_many :city_responders, :dependent => :destroy
has_many :members, :through => :responses
accepts_nested_attributes_for :recordings, :city_responders, :responses, :patients
validates_inclusion_of :reviewed, :in => [true, false], :allow_blank => true
validates_associated :patients, :responses, :city_responders, :if => :reviewed
...
class CityResponder < ActiveRecord::Base
before_destroy :check_call_reviewed
before_save :check_call_reviewed
before_create :check_call_reviewed
belongs_to :call
....
validates_presence_of :call
validates_datetime :arrival, :on_or_after => Proc.new { |city_responder| city_responder.call.time }, :on_or_before => Proc.new { |city_responder| city_responder.call.clear_time }, :if => proc { |city_responder| city_responder.call && city_responder.call.reviewed }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment