我的应用程序有错误。我有一个嵌套的 from,它在新页面中完美呈现,但不是在我想查看所有用户内容的页面中。这是错误:
NoMethodError in Resumes#index
Showing /Users/antonella/Desktop/resumin/resume/app/views/resumes/index.html.erb where line #10 raised:
undefined method `educations' for nil:NilClass
Extracted source (around line #10):
7: <%= resume.personal_detail.address %>
8: <%= resume.personal_detail.telephone %>
9: </li>
10: <% @resume.educations.each do |education| %>
11: <li>
12: <%= resume.education.school_name %>
13: <%= resume.education.city %>
Rails.root: /Users/antonella/Desktop/resumin/resume
简历.rb
class Resume < ActiveRecord::Base
has_one :personal_detail
has_many :educations, :dependent => :destroy
accepts_nested_attributes_for :personal_detail
attr_accessible :personal_detail_attributes
validates_associated :personal_detail
accepts_nested_attributes_for :educations, :reject_if => lambda { |a| a[:education].blank? }, :allow_destroy => true
attr_accessible :education_attributes
validates_associated :education
end
resumes_controller.rb
def index
@resumes = Resume.all
end
教育.rb
class Education ‹ ActiveRecord::Base
belongs_to :resume
attr_accessible :school_name, :degree, :dates_attended, :type_of_study, :field_of_study, :city, :country
end
索引.html
<h1>All resumes</h1>
<ul>
<% @resumes.each do |resume| %>
<li>
<%= resume.personal_detail.firstname %>
<%= resume.personal_detail.lastname %>
<%= resume.personal_detail.address %>
<%= resume.personal_detail.telephone %>
</li>
<% @resume.educations.each do |education| %>
<li>
<%= resume.education.school_name %>
<%= resume.education.city %>
<%= resume.education.country %>
<%= resume.education.dates_attended %>
<%= resume.education.degree %>
<%= resume.education.type_of_study %>
<%= resume.education.field_of_study %>
</li>
<% end %>
<% end %>
</ul>