我认为这个很简单......但是我不明白。我在两个模型(组合和canvas_price)之间有一个has_many关系:
combination.rb:
class Combination < ActiveRecord::Base
has_many :canvas_prices, :dependent => :delete_all
accepts_nested_attributes_for :canvas_prices,
:allow_destroy => true,
:reject_if => lambda { |a| a[:name].blank? }
end
canvas_price.rb:
class CanvasPrice < ActiveRecord::Base
belongs_to :combination
end
在我的表单中,我有链接,可以通过JavaScript删除嵌套的CanvasPrice表单中的输入。
我的问题是,当我删除这些字段中的一个或多个并更新组合时,相关的CanvasPrices不会被删除,尽管我想要删除的CanvasPrices不在我的参数中。我如何实现这一目标?
答案 0 :(得分:0)
好的,非常简单......就像在隐藏输入的帮助下添加_delete-param一样简单,e。 G。组合[canvas_prices] [0] [_ delete] = true。
我认为可以直接在has_many或accepts_nested_attributes_for方法中配置此行为。