这是对上一篇文章的重新编辑
我以前认为这个问题与茧有关,但现在我不这么认为,因为下面的代码甚至没有调用茧
每次我更新包含嵌套属性的表单时,嵌套记录的数量都会翻倍。据我所知,在调用表单时会发生这种情况,因为在我做任何事情之前我会立即看到更新,并且表单显示有重复的条目
我在下面的 HAML 中有我的视图的相关代码 -
%h3 Household Members
= f.simple_fields_for :neighbors do |neighbor|
= render 'neighbor_fields', :f => neighbor
我在控制器上使用了像样的曝光,所以控制器看起来像这样:
class HouseholdsController < ApplicationController
expose(:households)
expose(:household, strategy: StrongParametersStrategy)
def create
if household.save
redirect_to households_path, notice: 'Household was successfully created.'
else
render 'new'
end
end
def update
if household.save
redirect_to households_path, notice: 'Household was successfully updated.'
else
render 'edit'
end
end
def destroy
household.destroy
redirect_to households_path, notice: 'Household deleted.'
end
如何防止嵌套属性加倍?