How to upload more than one image in Rails using simple_form?

I'm using Rails 3.2, Carrierwave and simple_form.

Currently, everything is working fine with one image upload with the following code:

<%  @product.images.build if @product.images.blank? %>
<%= f.simple_fields_for :images do |img| %>
  <% unless @product.images.first.file.blank? %>
      <div class="control-group">
         <label class="controls"><%= image_tag @product.images.first.file %></label>
      </div>   
      <%= img.input :_destroy, :label => "Remove", :as => :boolean %>
  <% end %>
      <%= img.input :file, :as => :file, :label => "Picture", input_html: { class: "input-hundredpercent" } %>
<% end %>

However, how can I turn this nested form for multi image upload?

Answers


You could try Ryan Bate's nested_form gem (https://github.com/ryanb/nested_form).

Also refer to his railscast about this topic: http://railscasts.com/episodes/196-nested-model-form-revised


Need Your Help

create a grayscale image

python python-imaging-library

I am reading binary data from one file that specifies intensity values across x and y coordinates (not a open-source image format) and want to convert it to a PNG image (or other widely supported f...

twisted python garbage collection

python garbage-collection twisted

I currently am developing a python twisted server to use as a message processing application. I have come across an odd problem.