Reputation: 1358
I have a Gallery model and an Images model, where a Gallery has_and_belongs_to_many Images.
Right now, new images are uploaded via the images form, and a gallery's images are selected from the gallery form using checkboxes. I'd like to keep the existing checkbox selection method for existing images, but also be able to upload new images from within the gallery form (and simultaneously create the association between the new image and the gallery).
Here is my gallery form:
<%= semantic_form_for [:admin, @gallery] do |g| %>
<%= g.inputs "Details" do %>
<%= g.input :title %>
<%= g.input :images, :as => :check_boxes, :label_method => Proc.new { |image| image_tag(image.thumb_path, :alt => "") + content_tag("h3", image.title) } %>
<% end %>
<%= g.inputs "Images" do %>
<% g.has_many :images do |i| %>
<%= i.input :title %>
<%= i.input :asset, :as => :file %>
<% end %>
<% end %>
<%= g.buttons %>
<% end %>
I am seeing the following error when I browse to the form:
undefined method `has_many' for #<Formtastic::SemanticFormBuilder:0xb410d4c>
I'm still learning Rails and I'm totally new to ActiveAdmin, so I may be missing something obvious here. I'm happy to provide more context if that would be helpful.
Thank you for any assistance you can provide!
Upvotes: 2
Views: 734
Reputation: 3224
Assuming you have accepts_nested_attributes set up ...
First create a blank image
@gallery.images.build
then build input fields for the new image
<% g.inputs :for => :images do |image| %>
<% if image.new_record? %>
<%= image.input :title %>
<%= image.input :asset, :as => :file %>
<% end %>
<% end %>
Upvotes: 1