2011-03-16 55 views
3

我通过导轨协会教程http://guides.rubyonrails.org/association_basics.html预约时间表

我想进一步扩大这种模式适合我的需要去:

class Physician < ActiveRecord::Base 
    has_many :appointments 
    has_many :patients, :through => :appointments 
end 

class Appointment < ActiveRecord::Base 
    belongs_to :physician 
    belongs_to :patient 
end 

class Patient < ActiveRecord::Base 
    has_many :appointments 
    has_many :physicians, :through => :appointments 
end 

我应该怎样做一个模型,has_many约会协会与Physician

例如:

class Physician < ActiveRecord::Base 
    has_many :appointments 
    has_many :availableappointments 
    has_many :patients, :through => :appointments 
end 

class Availableappointment < ActiveRecord::Base 
    belongs_to :physician 
end 

我难以理解如何在模型中存储不同的时间范围?可以说医生可以从上午8点到下午3点,每次约会时间为30分钟(8:30-9,9-9:30,9:30-10)......如何将这些信息存储在DB或Availableappointment型号

回答

0

首先,我会将Availableappointment重命名为Availability。

为每个30分钟的时间段创建可用性实例。您可以以编程方式为Physician预先填充它,或者医生自己在管理部分添加它们。您需要此视图让医生以任何方式查看他的可用约会,因为可用性实例对每位医师都是唯一的,并且医师总是可以删除/重新添加可用性。

然后将从可视化医师可用性的视图创建约会。当根据可用性创建约会时,请删除可用性。