Multiple image upload finished

This commit is contained in:
San Wai Lwin
2018-03-26 11:40:04 +06:30
parent 110dc80f0c
commit 186353acb0
4 changed files with 9 additions and 22 deletions

View File

@@ -47,15 +47,13 @@ class Settings::ShopsController < ApplicationController
# PATCH/PUT /settings/shops/1
# PATCH/PUT /settings/shops/1.json
def update
respond_to do |format|
if @settings_shop.update(shop_params)
if params[:display_images].present?
params[:display_images]['image'].each do |a|
aa = a.read
base64_encoded = Base64.encode64(aa)
byebug
@display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => base64_encoded)
params[:display_images][:image].each do |a|
@aa = Base64.encode64(a.read)
@display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => "data:image/jpeg;base64,"+@aa)
end
end
format.html { redirect_to settings_shops_url, notice: 'Shop was successfully updated.' }

View File

@@ -1,5 +1,5 @@
class DisplayImage < ApplicationRecord
mount_uploader :image, DisplayImageUploader
#mount_uploader :image, DisplayImageUploader
belongs_to :shop
end

View File

@@ -44,25 +44,14 @@
<div class="panel padding-10">
<div class="form-group">
<div class="menu-item-img">
<%= f.fields_for :display_images do |p| %>
<div class="field">
<%= image_tag p.object.image, :class => "img-thumbnail" %>
<%= link_to "Destroy", settings_shop_display_image_path(p.object), method: :delete %>
</div>
<% end %>
<%= image_tag "#{p.object.image}", :class => "img-thumbnail" %>
<%= link_to "Destroy", settings_shop_display_image_path(p.object), method: :delete %>
<% end %>
</div>
</div>
</div>
<%= f.file_field :image, :multiple => true, name: "display_images[image][]" %>
<!-- <%= f.fields_for :display_images do |p| %>
<div class="field">
<%= p.label :image %><br>
<%= p.file_field :image, :multiple => true, name: "display_images[image][]" %>
</div>
<% end %> -->
<div class="form-actions p-l-15">
<%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %>

View File

@@ -103,7 +103,7 @@
<td style="width:20%">Shop Images</td>
<td>
<% @display_images.each do |p| %>
<%= image_tag p.image , :size => '200x200'%><br>
<%= image_tag "#{p.image}" %>
<% end %>
</td>
</tr>