示例模型:
class Person
has_many :auto_mappings, dependent: :destroy
class Vehicle
has_many :auto_mappings
class AutoMapping
belongs_to :person
belongs_to :vehicle
validates :person,
:vehicle,
:usage,
presence: true
在Person
上的“创建/编辑”的ActiveAdmin表单中,我为嵌套的f.has_many
资源添加了一个输入AutoMapping
,以便一次添加一个AutoMapping
,效果很好。我想要完成的是以某种方式添加一个按钮,为每个AutoMapping
Vehicle
添加Person
。
有没有办法实现这个目标还是我应该采取另一个方向?
Person
的示例AA表单:
form do |f|
f.inputs 'Details' do
f.input :name
f.input :age
f.has_many :auto_mappings, class: 'auto_mapping' do |item|
item.input :vehicle, include_blank: false, input_html: {class: "vehicle", disabled: item.object.persisted?}
item.input :usage,
as: :select,
collection: %w[drive ride both]
include_blank: false
end
end
# Maybe a custom member action to "Create Person with all Auto Mappings"?
# I would prefer to auto populate the form page with `AutoMappings` rather than create them all on Submit if possible.
f.actions
end
谢谢!
答案 0 :(得分:0)
您必须扩展has_many.es6才能进行Ajax调用并添加项目。