Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @space = Space.find(params[:id])
- class SpacesController < ApplicationController
- before_action :set_space, except: [:index, :new, :create]
- before_action :authenticate_user!, except: [:show]
- def update
- if @space.update(space_params)
- flash[:notice] = "Saved!"
- else
- flash[:notice] = "Something went wrong. Please check your submission and try again."
- end
- redirect_back(fallback_location: request.referer)
- end
- def delete_image_attachment
- @space_image = ActiveStorage::Blob.find_signed(params[:id])
- @space_image.purge_later
- redirect_to listing_space_path(@space)
- end
- private
- def set_space
- @space = Space.find(params[:id])
- end
- def space_params
- params.require(:space).permit(:space_name, :space_type, :description, space_image: [])
- end
- end
- <div>
- <% if @space.image.attached? %>
- <% @space.image.each do |image| %>
- <%= image_tag image %>
- <span>
- <%= link_to '<- Remove', delete_image_attachment_space_url(image.signed_id),
- method: :delete,
- data: { confirm: 'Are you sure?' } %>
- <i class="fas fa-trash"></i>
- </span>
- <% end %>
- <% end %>
- </div>
- resources :spaces, except: [:edit] do
- member do
- get 'listing'
- delete :delete_image_attachment
- end
- end
Add Comment
Please, Sign In to add comment