我使用http://guides.rubyonrails.org/來學習ruby &導軌。我在加入三張桌子時遇到問題。 ,所以我做了新的項目,因爲這例子:http://guides.rubyonrails.org/association_basics.html#the-has_many_through-association我有三個表醫生,預約&患者在Rails3中加入三張表
型號:
physician.rb
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
attr_accessible :name
end
appointment.rb
class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
attr_accessible :appointment_date, :patient_id, :physician_id
end
patient.rb
class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, :through => :appointments
attr_accessible :name
end
我想顯示患者姓名,醫師姓名& appointment_date。這個怎麼做。 在此先感謝。
你有這些模型建立的控制器和視圖? –
是的,我擁有所有三種型號的控制器和視圖。 –
那麼,你只是想知道如何訪問視圖中的模型及其關聯? –