Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. def photo_upload
  2. @images = @tool.images
  3. end
  4.  
  5. def delete_image_attachment
  6. @images = ActiveStorage::Attachment.find(params[:id])
  7. @images.purge
  8. redirect_back(fallback_location: request.referer)
  9. end
  10.  
  11.  
  12. private
  13. def set_tool
  14. @tool = Tool.find(params[:id])
  15. end
  16.  
  17. def is_authorised
  18. redirect_to root_path, alert: "You don't have permission" unless current_user.id == @tool.user_id
  19. end
  20.  
  21. def tool_params
  22. params.require(:tool).permit(:tool_type, :power_type, :accessories, :brand, :listing_name, :summary, :address, :is_machine,
  23.  
  24. :is_hand, :is_cordless, :is_cord, :price, :active ,images: [])
  25. end
  26.  
  27. end
  28.  
  29. <% if @tool.images.attached? %>
  30.  
  31. <div class="panel panel-default">
  32. <div class="panel-heading">
  33. Photo Display
  34. </div>
  35. <br>
  36. <div class="row">
  37. <% @tool.images.each do |image| %>
  38. <div class="col-md-4">
  39. <div class="panel panel-default tools-gallery-panel">
  40. <div class="panel-heading preview ">
  41. <%= link_to image_tag(image, class:"img-thumbnail tools-gallery"), image %>
  42. </div>
  43. <div class="panel-body">
  44. <span class="pull-right">
  45. <i class="fa fa-trash-o fa-lg" aria-hidden="true"></i>
  46. <%= link_to "Remove", delete_image_attachment_tool_path(image), method: :delete, data: {confirm: "Are you sure?"} %>
  47. </span>
  48. </div>
  49. </div>
  50. </div>
  51. <% end %>
  52. <% end %>
  53.  
  54. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement