Skip to content

Instantly share code, notes, and snippets.

@fabrinal
Created June 1, 2015 12:47
Show Gist options
  • Save fabrinal/bdc1aca78b7161e7fbd5 to your computer and use it in GitHub Desktop.
Save fabrinal/bdc1aca78b7161e7fbd5 to your computer and use it in GitHub Desktop.
Form sample code to do multiple photos upload inside photo gallery form
<%= form_for(@photo_gallery,:html => {multipart: true}) do |f| %>
<% if @photo_gallery.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@photo_gallery.errors.count, "error") %> prohibited this photo_gallery from being saved:</h2>
<ul>
<% @photo_gallery.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :description %><br>
<%= f.text_field :description %>
</div>
<div class="field">
<%= f.label 'Photos' %><br>
<% 10.times do |i| %>
Photo <%= i + 1 %> &nbsp;
<%= file_field_tag "photos[#{i}]", accept: 'image/png,image/jpeg' %> &nbsp;
<%= @photo_gallery.photos[i].nil? ? '' : label_tag(@photo_gallery.photos[i].image_file_name,nil,id: "photo#{@photo_gallery.photos[i].id}") %> &nbsp;
<br><br>
<% end %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment