0
In this video(10秒)您可以看到嵌套屬性僅在更改父模型時才更新。嵌套表單子只在父更改時更新
使用rails 3.0.0.beta和full project is on github。模型和形式
摘要:
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
我一直在控制檯中測試,並且只適用於Rails 2.3.5,在Rails 3.0上沒有更新Assignment。 – nanda 2010-03-20 03:43:00
很酷,很高興知道。感謝功課南大! – Chap 2010-03-20 14:29:44
在軌道跟蹤器上打開票並添加了失敗的單元測試以演示: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4242-nested-child-only-updates-if -parent-changes – Chap 2010-03-20 15:16:56