accept_nested_attributes, reject_if doesn't work.

class Post < ActiveRecord::Base
  validates :name, :presence => true
  validates :title, :presence => true,
            :length => { :minimum => 5 }
  has_many :comments, :dependent => :destroy
  has_many :tags

  accepts_nested_attributes_for :tags, :allow_destroy => :true,
    :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? or v.nil? } }
end

rails c

irb(main):001:0> post=Post.first
=> #<Post id: 1, name: "prova", title: "titolo prova", content: "prova
1", created_at: "2011-02-01 10:03:10", updated_at: "2011-02-01
10:03:10">

irb(main):002:0> post.tags.create()
=> #<Tag id: 5, name: nil, post_id: 1, created_at: "2011-02-11
13:19:22", updated_at: "2011-02-11 13:19:22">
irb(main):003:0>

irb(main):003:0> post.valid?
=> true

Tags has blank or nil attributes but it is saved.
Why I have put :reject_if => proc { |attrs| attrs.all? { |k, v|
v.blank? or v.nil? } } for tags?

Looking at http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

I think accepts_nested_attributes expects an #{association}_attributes key/value pair to be passed

as an attribute to the parent object, in this case Post.

doing post.tags.create doesn’t pass by accepts_nested_attributes_for but the normal Tag.create.