我必须建模:
class Patient < ActiveRecord::Base
attr_accessible :bis_gultigkeit, :geburtsdatum, :krankenkassennummer, :kvbereich, :landercode, :name, :namenszusatz, :plz, :statuserganzung, :strasse, :titel, :versichertennumer, :versichertenstatus, :vorname, :wohnort, :geschlecht, :telefon, :email, :gewicht
has_many :diagnosis
end
class Diagnose < ActiveRecord::Base
attr_accessible :beschreibung, :code, :seite, :sicherheit, :typ, :patient_id
belongs_to :patient
end
如何看待两个模型有关联。 所以我想在患者展示页面上显示他的所有诊断。
def show
@patient = Patient.find(params[:id])
@diagnosis = @patient.diagnosis
respond_to do |format|
format.html # show.html.erb
format.json { render json: @patient }
end
end
在我看来,我打电话:
<%= @diagnosis.inspect %>
但不知怎的,我得到了错误:
uninitialized constant Patient::Diagnosi
我无法解释为什么我会收到此错误?为什么说Diagnosi?我的意思是我的型号名称是Diagnose!感谢
答案 0 :(得分:1)
您可以调用Diagnose.class_name.pluralize来查看rails如何将其复数化。 我猜这是“诊断”,所以你打电话:
@diagnoses = @patient.diagnoses
和
<%= @diagnoses.inspect %>