Rails 2.3 : Nested Attributes / Nested Object Forms
accepts_nested_attributes_for / fields_for
Nested attributes allow you to save attributes on associated records through the parent.
automatic (and atomic) saving of a record together with its associated children, child-aware validations, and support for nested forms.
class Customer < ActiveRecord::Base has_many :orders accepts_nested_attributes_for :orders, :allow_destroy => true end
<% form_for @customer do |customer_form| %> <%= customer_form.text_field :name %> <% customer_form.fields_for :orders do |order_form| %> <%= order_form.text_field :number %> <% unless order_form.object.new_record? %> <%= order_form.check_box :_delete %> <% end %> <% end %> <%= customer_form.submit %> <% end %>
Ruby on Rails 2.3 Release Notes - 4.1 Nested Attributes
Ruby on Rails 2.3 Release Notes - 6.1 Nested Object Forms
Module: ActiveRecord::NestedAttributes::ClassMethods
Module: ActionView::Helpers::FormHelper
Nested AttributesとNested Model Formsを使って親子オブジェクトを一括で登録/変更するには