Created
June 1, 2015 12:47
-
-
Save fabrinal/bdc1aca78b7161e7fbd5 to your computer and use it in GitHub Desktop.
Form sample code to do multiple photos upload inside photo gallery form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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 %> | |
<%= file_field_tag "photos[#{i}]", accept: 'image/png,image/jpeg' %> | |
<%= @photo_gallery.photos[i].nil? ? '' : label_tag(@photo_gallery.photos[i].image_file_name,nil,id: "photo#{@photo_gallery.photos[i].id}") %> | |
<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