0
내 업데이트 기능은 제출시 모델의 중첩 항목에 대한 레코드를 두 배로 늘립니다.레일즈가 update_attributes의 레코드를 두 배로 만듭니다.
fields_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) 및 해당 답변을 확인 했습니까? –