2013-08-29 24 views
0

我不得不型號:虛假的名字?患者:: Diagnosi

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!謝謝

回答

1

你可以調用Diagnose.class_name.pluralize看看rails是如何複用它的。 我猜是 「診斷」,所以你shoudl撥打:

@diagnoses = @patient.diagnoses 

<%= @diagnoses.inspect %>