Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def photo_upload
- @images = @tool.images
- end
- def delete_image_attachment
- @images = ActiveStorage::Attachment.find(params[:id])
- @images.purge
- redirect_back(fallback_location: request.referer)
- end
- private
- def set_tool
- @tool = Tool.find(params[:id])
- end
- def is_authorised
- redirect_to root_path, alert: "You don't have permission" unless current_user.id == @tool.user_id
- end
- def tool_params
- params.require(:tool).permit(:tool_type, :power_type, :accessories, :brand, :listing_name, :summary, :address, :is_machine,
- :is_hand, :is_cordless, :is_cord, :price, :active ,images: [])
- end
- end
- <% if @tool.images.attached? %>
- <div class="panel panel-default">
- <div class="panel-heading">
- Photo Display
- </div>
- <br>
- <div class="row">
- <% @tool.images.each do |image| %>
- <div class="col-md-4">
- <div class="panel panel-default tools-gallery-panel">
- <div class="panel-heading preview ">
- <%= link_to image_tag(image, class:"img-thumbnail tools-gallery"), image %>
- </div>
- <div class="panel-body">
- <span class="pull-right">
- <i class="fa fa-trash-o fa-lg" aria-hidden="true"></i>
- <%= link_to "Remove", delete_image_attachment_tool_path(image), method: :delete, data: {confirm: "Are you sure?"} %>
- </span>
- </div>
- </div>
- </div>
- <% end %>
- <% end %>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement