I'm trying to put an ff.inputs in a f.inputs in regards of a double nested object but the ff.inputs doesn't show up. When I put it in a partial it shows up but duplicates the fields.
Does anyone know a way around this?
Form:
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
When using the partial this is it:
<%= 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 %>
My fix for this was to just put everything in the form partial and just call the partial.
So in active admin I did:
form partial: 'form'
and in brought in the brand detail fields and logo into the partial.
This also allowed me to call image and banner partials that I could before.
Still let me know if there's a better way to do this.