0

ネストされたフォームを送信するときに問題が発生しています。

私の2つのモデル:

#PLANNING MODEL
class Planning < ActiveRecord::Base
   has_many :periods
   belongs_to :plannable, polymorphic: true
   attr_accessible :quantity, :periods_attributes
   accepts_nested_attributes_for :periods
end

#PERIOD MODEL
class Period < ActiveRecord::Base
   belongs_to :planning
   attr_accessible :planned_quantity, :planning_id
end

そして私の形で:

 ...
 <% @planning.periods.each do |period| %>
   <%= f.fields_for(period) do |builder| %>
     <%= builder.label :planned_quantity, "Planned quantity" %>
     <%= builder.number_field :planned_quantity%>
   <%end%>
 <%end%>
 ...

次のように表示されると、送信するまで、すべてが思いどおりに表示されます。

Can't mass-assign protected attributes: period

誰かが私を助ける方法を知っていますか? ウェブ全体を検索しています...

ありがとう!

4

2 に答える 2

0

@planning.periods.eachは必要ありません。これを行うだけです

<%= f.fields_for :periods do |builder| %>
  <%= builder.label :planned_quantity, "Planned quantity" %>
  <%= builder.number_field :planned_quantity%>
<% end %>
于 2013-10-30T14:15:10.700 に答える