Моя функция обновления удваивает записи для вложенных элементов в модели на submit.Рельсы удваивают записи на update_attributes
Тот, который НЕ находится в полях_for работает как ожидающий, но каждая запись в fields_for удваивается.
Что мне не хватает? Любая помощь будет высоко оценен
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) и его ответы? –