I think this one is pretty simple… But i don´t get it. I have a has_many-relationship between two models (combination and canvas_price):
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
In my form i have links which delete inputs in the nested CanvasPrice-form via JavaScript.
My problem is that when i delete one or more of these fields and update the combination, the associated CanvasPrices aren´t deleted, though the CanvasPrices which i want to delete are NOT in my params. How do i achieve this?
Ok, pretty simple… It was as easy as adding a _delete-param with help of a hidden input, e. g. combination[canvas_prices][0][_delete] = true.
I thought this behaviour could be configured directly in the has_many or accepts_nested_attributes_for method.