Files
grecia/app/controllers/admin/poll/questions/answers/images_controller.rb
Javi Martín d050c04bb0 Use a button to destroy poll question answer images
As mentioned in commits 5311daadf and bb958daf0, using links combined
with JavaScript to generate POST (or, in this case, DELETE) requests to
the server has a few issues.

Note that the AJAX response stopped working after replacing the link
with a button. Not sure about the reason, but, since this is one of the
very few places where we use AJAX calls to delete content, the easiest
solution is to stop using AJAX and be consistent with what we do in the
rest of the admin section.
2024-04-17 16:44:10 +02:00

42 lines
929 B
Ruby

class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseController
include ImageAttributes
load_and_authorize_resource :answer, class: "::Poll::Question::Answer"
load_and_authorize_resource only: [:destroy]
def index
end
def new
end
def create
@answer.attributes = images_params
authorize! :update, @answer
if @answer.save
redirect_to admin_answer_images_path(@answer),
notice: t("flash.actions.create.poll_question_answer_image")
else
render :new
end
end
def destroy
@image.destroy!
redirect_to admin_answer_images_path(@image.imageable),
notice: t("flash.actions.destroy.poll_question_answer_image")
end
private
def images_params
params.require(:poll_question_answer).permit(allowed_params)
end
def allowed_params
[:answer_id, images_attributes: image_attributes]
end
end