Nested form child only updates if parent changes.
- by chap
In this video (10 sec) you can see that the nested attribute is only updated if it's parent model is changed.
Using rails 3.0.0.beta and full project is on github.
Summary of models and form:
class Project < ActiveRecord::Base
has_many :tasks
accepts_nested_attributes_for :tasks
end
class Task < ActiveRecord::Base
belongs_to :project
has_many :assignments
accepts_nested_attributes_for :assignments
end
class Assignment < ActiveRecord::Base
belongs_to :task
end
form_for(@project) do |f|
Project: f.text_field :name
f.fields_for :tasks do |task_form|
Task: task_form.text_field :name
task_form.fields_for :assignments do |assignment_form|
Assignment: assignment_form.text_field :name
end
end
f.submit
end