ウェブサービスを作っています。

api.rubyonrails.org の NestedAttributes の説明が間違ってる気がする

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


accepts_nested_attributes_for の :allow_destroy の説明で

class Member < ActiveRecord::Base
  has_many :posts
  accepts_nested_attributes_for :posts, :allow_destroy => true
end

params = {'member' => { 'name' => 'joe', 'posts_attributes' => {
  '2' => { '_delete' => '1' }
}}}
member.attributes = params['member']
member.posts.detect { |p| p.id == 2 }.marked_for_destruction? # => true

とあるんですが、true 返ってきません。
たぶん、params['member']['posts_attributes'] のキーの 2 は関係なくて、'id' => 2 を指定しないといけないと思う。だから、

class Member < ActiveRecord::Base
  has_many :posts
  accepts_nested_attributes_for :posts, :allow_destroy => true
end

params = {'member' => { 'name' => 'joe', 'posts_attributes' => {
  '0' => { 'id' => 2, '_delete' => '1' }
}}}
member.attributes = params['member']
member.posts.detect { |p| p.id == 2 }.marked_for_destruction? # => true

でうまくいく気がする。
NestedAttributes のコードとか、おそらくきっと相当複雑。