class User < ActiveRecord::Base
has_many :medicalhistory
end
Mdedicalhistory模型
class Medicalhistory < ActiveRecord::Base
belongs_to :user #foreign key -> user_id
accepts_nested_attributes_for :user
end
错误
undefined method `lastname' for #<ActiveRecord::Relation:0xb6ad89d0>
#this works
@medicalhistory = Medicalhistory.find(current_user.id)
print "\n" + @medicalhistory.lastname
#this doesn't!
@medicalhistory = Medicalhistory.where("user_id = ?", current_user.id)
print "\n" + @medicalhistory.lastname #error on this line
什么是错误信息? – 2011-05-14 21:33:33
'@ medicalhistory.first.lastname'是否有效? – Zabba 2011-05-14 21:38:17
:(是的,这是....洞察? – Omnipresent 2011-05-14 21:39:11