活动管理员在输入中输入输入

时间:2016-11-28 20:33:21

标签: ruby-on-rails forms activeadmin formtastic

我试图在f.inputs中设置一个关于双嵌套对象的ff.input,但是ff.inputs没有显示出来。当我把它放在一个部分时它显示但重复字段。

有没有人知道解决这个问题?

形式:

form do |f|
f.inputs 'Brand Details' do
  f.input :name
  f.input :heritage
end

f.inputs 'Logo', for: [:logo, f.object.logo || Image.new ] do |ff|
  ff.input :file, as: :file, hint: (ff.template.image_tag(ff.object.file.url) if ff.object.file?)
  ff.input :_destroy, as: :boolean, label: 'Remove' unless ff.object.new_record?
end


# render partial: 'banner_form'

f.inputs 'Heritage Banner', for: [:heritage_banner, f.object.heritage_banner || Banner.new] do |hb|
  hb.input :name
  hb.inputs 'Desktop Image*', for: [:desktop_image, hb.object.desktop_image || Image.new ] do |di|
    di.input :file, label: 'Image', as: :file, hint: (di.template.image_tag(di.object.file.url) if di.object.file?)
    di.input :_destroy, as: :boolean, :label => 'Remove' unless di.object.new_record?
  end
  hb.inputs 'Mobile Image*', for: [:mobile_image, hb.object.mobile_image || Image.new ] do |mi|
    mi.input :file, label: 'Image', as: :file, hint: (mi.template.image_tag(mi.object.file.url) if mi.object.file?)
    mi.input :_destroy, as: :boolean, :label => 'Remove' unless mi.object.new_record?
  end
  hb.input :video_url
end

f.inputs 'Header Banner', for: [:header_banner, f.object.header_banner || Banner.new] do |hb|
  hb.input :name
  hb.inputs 'Desktop Image*', for: [:desktop_image, hb.object.desktop_image || Image.new ] do |di|
    di.input :file, label: 'Image', as: :file, hint: (di.template.image_tag(di.object.file.url) if di.object.file?)
    di.input :_destroy, as: :boolean, :label => 'Remove' unless di.object.new_record?
  end
  hb.inputs 'Mobile Image*', for: [:mobile_image, hb.object.mobile_image || Image.new ] do |mi|
    mi.input :file, label: 'Image', as: :file, hint: (mi.template.image_tag(mi.object.file.url) if mi.object.file?)
    mi.input :_destroy, as: :boolean, :label => 'Remove' unless mi.object.new_record?
  end
  hb.input :video_url
end

f.actions
end

当使用partial时,这就是:

<%= semantic_form_for [:admin, @brand] do |f| %>
<%= f.inputs 'Heritage Banner', for: [:heritage_banner, f.object.heritage_banner || Banner.new] do |hb| %>
    <%= hb.input :name %>
    <%= hb.inputs 'Desktop Image*', for: [:desktop_image, hb.object.desktop_image || Image.new ] do |di| %>
        <%= di.input :file, label: 'Image', as: :file, hint: (di.template.image_tag(di.object.file.url) if di.object.file?)  %>
        <%= di.input :_destroy, as: :boolean, :label => 'Remove' unless di.object.new_record?  %>
    <% end %>

    <%= hb.inputs 'Mobile Image*', for: [:mobile_image, hb.object.mobile_image || Image.new ] do |mi| %>
        <%= mi.input :file, label: 'Image', as: :file, hint: (mi.template.image_tag(mi.object.file.url) if mi.object.file?)  %>
        <%=  mi.input :_destroy, as: :boolean, :label => 'Remove' unless mi.object.new_record?  %>
    <% end %>

    <%= hb.input :video_url  %>
<% end %>

<%= f.inputs 'Header Banner', for: [:header_banner, f.object.header_banner || Banner.new] do |hb| %>
    <%= hb.input :name %>
    <%= hb.inputs 'Desktop Image*', for: [:desktop_image, hb.object.desktop_image || Image.new ] do |di| %>
        <%= di.input :file, label: 'Image', as: :file, hint: (di.template.image_tag(di.object.file.url) if di.object.file?)  %>
        <%= di.input :_destroy, as: :boolean, :label => 'Remove' unless di.object.new_record?  %>
    <% end %>

    <%= hb.inputs 'Mobile Image*', for: [:mobile_image, hb.object.mobile_image || Image.new ] do |mi| %>
        <%= mi.input :file, label: 'Image', as: :file, hint: (mi.template.image_tag(mi.object.file.url) if mi.object.file?)  %>
        <%=  mi.input :_destroy, as: :boolean, :label => 'Remove' unless mi.object.new_record?  %>
    <% end %>

    <%= hb.input :video_url  %>
<% end %>

1 个答案:

答案 0 :(得分:0)

我对此的解决方法是将表格中的所有内容放入局部,然后调用部分内容。

所以在主动管理员中我做了:

form partial: 'form'

并将品牌明细字段和徽标带入部分内容。

这也让我可以在之前调用图像和横幅部分。

仍然让我知道是否有更好的方法来做到这一点。