Tôi có ba mô hình được trình bày dưới dạng nhiều mô hình.Đường ray 3 Biểu mẫu nhiều mô hình với nhiều trường hợp mới của mô hình con
class Parent < ActiveRecord::Base
has_many :children
accepts_nested_attributes_for :children
end
class Child < ActiveRecord::Base
belongs_to :parent
has_many :other_children
accepts_nested_attributes_for :other_children
end
class OtherChild < ActiveRecord::Base
belongs_to :child
end
= form_for @parent do |f|
# fields for parent
= f.fields_for :children, @parent.children do |cf|
= cf.fields_for :other_children, @parent.children do |ocf|
# fields_for other child
= cf.fields_for :other_children, @parent.children.new do |ocf|
# fields_for other child
Hoạt động này trừ khi tôi sao chép nhóm con thứ hai thông qua jquery. Để rõ ràng hơn, các fields_for với mô hình new_child mới có một nút tạo kích hoạt một số jquery như $(new_child_form).clone().insertBefore($(new_child_form))
cho phép nhiều hơn một mô hình con được thêm vào trong cùng một biểu mẫu gửi. Tôi biết tôi có thể gửi từng mẫu con riêng lẻ qua ajax nhưng đây không phải là điều tôi muốn.
Đường ray đang nhận được nhiều hơn một parent[children_attributes][0][other_children_attributes][1]
và dường như chỉ sử dụng hình ảnh cuối cùng. Bất kỳ ý tưởng?