Appointment Time schedule in Rails
I am going through the rails association tutorial http://guides.rubyonrails.org/association_basics.html
I want to extend this model further to fit my needs:
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
end
class Appointment < ActiveRecord::Base
belongs_to :physician
belo开发者_如何学Cngs_to :patient
end
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, :through => :appointments
end
How should I make a model that has_many
appointments association with Physician
For example:
class Physician < ActiveRecord::Base
has_many :appointments
has_many :availableappointments
has_many :patients, :through => :appointments
end
class Availableappointment < ActiveRecord::Base
belongs_to :physician
end
I am stumped on how to store different time frames in the model? Lets say a physician is available from 8AM - 3PM with each appointment being 30 minutes (8:30-9, 9-9:30, 9:30-10)...how can I store this information in the DB or Availableappointment
model
First, I would rename Availableappointment to Availability.
Create instances of Availability for each 30 minute time slot. You can either pre-populate it for the Physician programmatically, or the Physician adds them himself in an admin section. You need this view for the Physician to see his Available appointments either way, because the Availability instances are unique to each Physician, and Physician can always remove/re-add Availability.
Then appointments will be created from a view which visualizes the Physician availabilities. When Appointment is created based off an Availability, remove the availability.
精彩评论