我想使用 ActiveAdmin::FormBuilder,因为我喜欢它允许生成嵌套模型的方式(主要是它的has_many
方法,它使用内联 javascript 生成漂亮的按钮以轻松创建和销毁嵌套对象)。
但是我想编辑表单本身,因为默认情况下它的外观占用太多空间。
有谁知道是否有自定义表单设计输出的好方法,但保留嵌套对象的嵌套方法?
这是一个带有注释的代码示例:
<%= semantic_form_for @item, builder: ActiveAdmin::FormBuilder do |f| %>
<% f.inputs "Item Details" do %>
<% f.input :keywords %>
<% f.input :description %>
<% end %>
<% f.inputs "Features", :id => "item_features" do %>
<% f.has_many :features, :header => "" do |feature| %>
<!-- all these fields are generated in separate rows, I want to fit them all to one row - so need to add some classes-->
<% feature.input :name, :label => "Feature Name" %>
<% feature.input :value, :label => "Feature Value" %>
<% feature.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove Feature' %>
<% end %>
<% end %>
<% f.inputs "Options", :id => "item_options" do %>
<% f.has_many :options, :header => "" do |option| %>
<!-- same thing here -->
<% option.input :name, :label => "Option Name" %>
<% option.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove Option' %>
<% end %>
<% end %>
<% f.actions %> <!-- here I want to add some classes to each button -->
<% end %>