문제

Ryan Daigle의 블로그 게시물을 가이드로 사용하여 내 사이트의 중첩 객체 양식을 구현하려고합니다.http://ryandaigle.com/articles/2009/2/1/what-s-new-in-ed-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|, 양식은 렌더링하지만 제출시 '알 수없는 속성 : step'오류가 발생합니다.

내가하는 일은 튜토리얼과 일치하는 것 같습니다. 무엇을 확인해야합니까? 감사.

도움이 되었습니까?

해결책

컨트롤러에서 무슨 일이 일어나고 있습니까? 아직 튜토리얼을 읽지 않았지만 지금 당장 뽑을 수없는 것 같습니다 (아래로?).

컨트롤러에서 "새로운"조치에서

@instruction = Instruction.new
@instruction.steps.build

이것은 인스턴스화 될 것입니다 Step 당신의 양식을 작성하기위한 "자리 표시 자"로서의 메모리에서. . . 적어도 이것은 내가 사용할 때 내 컨트롤러에서하는 일입니다. accepts_nested_attributes_for, 그리고 그것은 훌륭하게 작동합니다.

작동하는지 알려주세요. 일단 튜토리얼을 풀 수 있으면 편집해야 할 수도 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top