accepts_nested_attributes_for ignore blank values

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2011-02-10T23:08:34Z Indexed on 2011/02/10 23:25 UTC
Read the original article Hit count: 359

i have

class Profile
  has_many :favorite_books, :dependent => :destroy
  has_many :favorite_quotes, :dependent => :destroy

  accepts_nested_attributes_for :favorite_books, :allow_destroy => true
  accepts_nested_attributes_for :favorite_quotes, :allow_destroy => true
end

I have a dynamic form where you press '+' to add new textareas for creating new favorites. What i want to do is ignore the blank ones, I find this harder to sort through in the update controller than a non nested attribute.

What i have temporarily is a hack in the after_save callback deleting the empty records. Whats the most rails way to ignore these blank objects?

I dont want validation and errors, just a silent deletion/ignore.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby