rubyonrails apiをもう少し深く読む必要があります;)リンク
class Member < ActiveRecord::Base
has_many :posts
accepts_nested_attributes_for :posts
end
属性ハッシュを使用して、関連付けられた投稿モデルの属性を設定または更新できるようになりました。
idキーを持たないハッシュごとに、ハッシュにtrueと評価される_destroyキーも含まれていない限り、新しいレコードがインスタンス化されます。
params = { :member => {
:name => 'joe', :posts_attributes => [
{ :title => 'Kari, the awesome Ruby documentation browser!' },
{ :title => 'The egalitarian assumption of the modern citizen' },
{ :title => '', :_destroy => '1' } # this will be ignored
]
}}
member = Member.create(params['member'])
member.posts.length # => 2
member.posts.first.title # => 'Kari, the awesome Ruby documentation browser!'
member.posts.second.title # => 'The egalitarian assumption of the modern citizen'