Nested Attributesの書き方

RailsのNested_attributeの書き方。結局APIを読む羽目に。

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

One-to-many

You may also set a :reject_if proc to silently ignore any new record hashes if they fail to pass your criteria. For example, the previous example could be rewritten as:

class Member < ActiveRecord::Base
has_many :posts
accepts_nested_attributes_for :posts, :reject_if => proc { |attributes| attributes['title'].blank? }
end

params = { :member => {
:name => 'joe', :posts_attributes => [
{ :title => 'Kari, the awesome Ruby documentation browser!' },
{ :title => 'The egalitarian assumption of the modern citizen' },
{ :title => '' } # this will be ignored because of the :reject_if proc
]
}}