Ryan Daigle의 블로그 게시물을 가이드 (http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes)로 사용하여 내 사이트의 중첩 된 개체 양식을 구현하려고합니다. 어떤 이유로 든 중첩 된 양식 필드가 뷰에 나타나지 않습니다. 중첩 된 양식 필드가 나타나는 문제
class Instruction < ActiveRecord::Base
has_many :steps
accepts_nested_attributes_for :steps
end
class Step < ActiveRecord::Base
belongs_to :instruction
end
<% form_for @instruction do |instruction_form| %>
<%= instruction_form.error_messages %>
<p>
<%= instruction_form.label :title %><br />
<%= instruction_form.text_field :title %>
</p>
<p>
<%= instruction_form.label :difficulty %><br />
<%= instruction_form.text_field :difficulty %>
</p>
<% instruction_form.fields_for :steps do |step_form| %>
<%= step_form.label :explanation, 'Explanation: ' %>
<%= step_form.text_field :explanation %>
<% end %>
<p><%= instruction_form.submit "Submit" %></p>
<% end %>
내가 양식 만 제출시 렌더링 instruction_form.fields_for :steps do |step_form|
instruction_form.fields_for :step do |step_form|
에 변경
자습서와 일치하는 것으로 보입니다. 무엇을 확인해야합니까? 감사.
을 편집 할 수 있습니다 .steps.build. 튜토리얼을 되돌아 보면 '엑스트라'섹션을 읽어야한다는 것을 알았습니다. 도와 주셔서 감사합니다! – sutee
환상적! 그것은 어둠 속의 총 이었지만, 내가 accepts_nested_attributes_for를 사용할 때 알아 차 렸던 것은 이상한 것이었다 환호! – BushyMark