我使用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。这个怎么做。 在此先感谢。
你有这些模型建立的控制器和视图? –
是的,我拥有所有三种型号的控制器和视图。 –
那么,你只是想知道如何访问视图中的模型及其关联? –