cocoon icon indicating copy to clipboard operation
cocoon copied to clipboard

Empty object being created even if owning object has :reject_if => :all_blank set

Open kaizenx opened this issue 11 years ago • 1 comments

Exactly as it says

I have PurchaseDetails

class PurchaseDetail < ActiveRecord::Base
  has_many :purchases
  accepts_nested_attributes_for :purchases, :reject_if => :all_blank, :allow_destroy => true
end

This is still allowing an extra empty object to be created.

kaizenx avatar Sep 29 '15 11:09 kaizenx

You have to show some more information @kaizenx. Maybe you have some hidden fields in your form? Do you fill in default fields from within your controller? Do you have a select-dropdown which automatically selects the first value? What is posted to the controller? The code you show is pure rails code, so for me it is hard to guess the relation with cocoon now.

Or, if that is your question, I have tested in my own code before and can confirm this should work.

nathanvda avatar Sep 29 '15 12:09 nathanvda