如何在activeadmin中创建此表单?
<%= form_for(@album, :html => {:multipart => true}) do |f| %>
.....
<div class="field">
<%= f.label :apellido %><br />
<%= f.text_field :apellido %>
</div>
<div class="field">
<p>Hijos</p>
<%= f.fields_for :hijos do |builder| %><br /><br />
<%= builder.label :nombre, 'Nombre Hijo' %><br />
<%= builder.text_field :nombre %><br />
<%= builder.label :apodo, 'Apodo Hijo' %><br />
<%= builder.text_field :apodo %><br />
<%= builder.label :hijo_id, 'favorito' %>
**<%= f.radio_button :hijo_id, builder.object.id %>**
<% end %>
</div>
我需要把hijo_id
的选项放在:hijos
的for中
Try:
f.input :avatar_item_id, :as => :boolean, :value => app_f.object.id
But not work.
谢谢
一旦您将Album模型注册为ActiveAdmin资源,这应该就可以工作了:
form :html => {:multipart => true} do |f|
f.inputs "Principal" do
f.input :apellido
end
f.inputs "Hijos" do
f.has_many :hijos do |h|
h.input :nombre
h.input :apodo
h.input :favorito, :as => :check_box
end
end
f.buttons
end
如果您想将child
标记为收藏,则需要在hijos
表中使用布尔favorito
字段,而不是hijo_id
字段。