Guest User

Untitled

a guest
Aug 20th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. @space = Space.find(params[:id])
  2.  
  3. class SpacesController < ApplicationController
  4. before_action :set_space, except: [:index, :new, :create]
  5. before_action :authenticate_user!, except: [:show]
  6.  
  7.  
  8. def update
  9. if @space.update(space_params)
  10. flash[:notice] = "Saved!"
  11. else
  12. flash[:notice] = "Something went wrong. Please check your submission and try again."
  13. end
  14. redirect_back(fallback_location: request.referer)
  15. end
  16.  
  17.  
  18. def delete_image_attachment
  19. @space_image = ActiveStorage::Blob.find_signed(params[:id])
  20. @space_image.purge_later
  21. redirect_to listing_space_path(@space)
  22. end
  23.  
  24. private
  25. def set_space
  26. @space = Space.find(params[:id])
  27. end
  28.  
  29. def space_params
  30. params.require(:space).permit(:space_name, :space_type, :description, space_image: [])
  31. end
  32.  
  33. end
  34.  
  35. <div>
  36. <% if @space.image.attached? %>
  37. <% @space.image.each do |image| %>
  38. <%= image_tag image %>
  39. <span>
  40. <%= link_to '<- Remove', delete_image_attachment_space_url(image.signed_id),
  41. method: :delete,
  42. data: { confirm: 'Are you sure?' } %>
  43. <i class="fas fa-trash"></i>
  44. </span>
  45. <% end %>
  46. <% end %>
  47. </div>
  48.  
  49. resources :spaces, except: [:edit] do
  50. member do
  51. get 'listing'
  52. delete :delete_image_attachment
  53. end
  54. end
Add Comment
Please, Sign In to add comment