У меня есть три модели, представленные в форме нескольких моделей.
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
Это работает, за исключением случаев, когда я дублирую второй набор дочерних полей через jquery.Чтобы быть более понятным, fields_for с новой моделью other_child имеет кнопку создания, которая запускает некоторый jquery, такой как $(new_child_form).clone().insertBefore($(new_child_form))
, позволяющий добавить более одной дочерней модели в одну форму отправки.Я знаю, что могу отправить каждую дочернюю форму индивидуально через ajax, но это не то, что я хочу.
Rails получает более одного parent[children_attributes][0][other_children_attributes][1]
и, похоже, использует только последнюю.Есть идеи?