This project is archived and is in readonly mode.

#2501 ✓resolved
Mike Breen

:any_blank and :all_blank options for accepts_nested_attributes_for :reject_if

Reported by Mike Breen | April 15th, 2009 @ 06:06 PM | in 2.3.6

I'm seeing a pattern in my projects when using accepts_nested_attributes_for with the :reject_if option:

class Blog < ActiveRecord::Base
  has_many :posts
  has_one :author

  accepts_nested_attributes_for :author, :reject_if => proc { |attributes| attributes.all? {|k,v| v.blank?} }

  accepts_nested_attributes_for :posts, :reject_if => proc { |attributes| attributes.any? {|k,v| v.blank?} }

end

This patch allows you to pass the values :all_blank and :any_blank to :reject_if and will generate the proc for you.

class Blog < ActiveRecord::Base

  has_many :posts
  has_one :author

  accepts_nested_attributes_for :author, :reject_if => :all_blank
  accepts_nested_attributes_for :posts, :reject_if => :any_blank 

end

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>