0
私の更新機能は、サブミット時にモデル内のネストされたアイテムのレコードを2倍にします。Railsはupdate_attributesのレコードを2倍にします。
fields_forには含まれていませんが、expect_forとして機能しますが、fields_forのすべてのレコードは倍増しています。
私には何が欠けていますか? IDをprinter_paramsに:すべてのヘルプは非常にあなたが欠落している
def edit
@printer = Printer.find(params[:id])
end
def update
@printer = Printer.find(params[:id])
if @printer.update_attributes(printer_params)
redirect_to @printer
else
render 'edit'
end
end
def printer_params
params.require(:printer).permit(:model, colors_attributes: [:color], materials_attributes: [:material], printer_photos_attributes: [:image_url])
end
edit.html.erb
<%= form_for @printer, html: { multipart: true }, :url => url_for(:controller => 'printers', :action => 'update') do |p|%>
<%= p.text_field :model %>
<%= p.fields_for :colors do |color|%>
<%= color.text_field :color %>
<% end %>
<%= p.submit "Edit" %>
<% end %>
[この質問](http://stackoverflow.com/questions/9944065)とその回答を確認しましたか? –