私はこれらのモデルを持っています
class Course < ActiveRecord::Base
attr_accessible :name
has_many :teachers
end
class Teacher < ActiveRecord::Base
attr_accessible :id, :name, :course_id
belongs_to :course
has_many :evaluations
end
class Evaluation < ActiveRecord::Base
attr_accessible :teacher_id, :course_id
belongs_to :teacher
end
これは views/evaluations/index.html.erb ファイルです
<% @evaluations.each do |evaluation| %>
<tr>
<td><%= evaluation.teacher_id %></td>
<td><%= link_to 'Show', evaluation %></td>
<td><%= link_to 'Edit', edit_evaluation_path(evaluation) %></td>
<td><%= link_to 'Destroy', evaluation, :method => :delete, :data => { :confirm => 'Are you sure?' } %></td>
</tr>
<% end %>
先生の名前を次のように表示したい:
<td><%= evaluation.teacher.name %></td>
しかし、それは機能しません.Railsはこのエラーを示しています:
"undefined method `name' for nil:NilClass"
誰でも私を助けることができますか?