我在提交它時遇到了嵌套形式的問題。嵌套形式的質量賦值錯誤
我的兩個型號:
#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
有誰知道如何幫助我?正在搜索整個網絡...
謝謝!
您是否嘗試過加入':period'到規劃模型中的attr_accessible白名單? – rjz
@rjz是的,已經試過了,它返回錯誤'unknown attribute:period' – ianobraczka