모두 안녕하세요.중첩 된 양식 및 누에 고치. 정의되지 않은 메서드 'label'for nil : NilClass
Showing /app/views/dashboard/courses/_price.html.erb where line #1 raised:
undefined method `label' for nil:NilClass
다음
있는 코드 _form.html.erb
:
<%= simple_form_for [:dashboard, @course], html: { multipart: true } do |f| %>
//////
<%= f.fields_for :prices do |p|%>
<%= render 'price', :f => 'prices' %>
<% end %>
<%= link_to_add_association 'Add', f, :prices %>
////////
_price.html.erb
:
<%= p.label :price %>
<%= p.text_field :price %>
<%= p.label :desc %>
<%= p.text_field :description %>
<%= link_to_remove_association "remove", f %>
모델 :
내가/courses/new
(또는
/courses/some_id/edit
)를 열 때, 브라우저는이 오류를 반환
class Price < ActiveRecord::Base
belongs_to :course
end
class Course < ActiveRecord::Base
has_many :prices
accepts_nested_attributes_for :prices, :reject_if => :all_blank, :allow_destroy => true
end
이 오류를 해결하는 방법? 왜 그것이 발생 했습니까?
당신은'simple_form_for'을 사용하고 있습니다,''%% f.simple_fields_for : prices do | p | %>' – Pavan
고마워요, Pavan. 그것은 작동합니다! – DmitrySharikov
제 제안이나 요시지 씨의 대답과 함께? – Pavan