Load question from load_and_authorize_resource in answers controller

This commit is contained in:
taitus
2022-09-09 10:57:53 +02:00
parent 8b4cd13675
commit 01005b50cb

View File

@@ -7,12 +7,11 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
load_and_authorize_resource :question, class: "::Poll::Question" load_and_authorize_resource :question, class: "::Poll::Question"
def new def new
@answer = ::Poll::Question::Answer.new @answer = @question.answers.new
end end
def create def create
@answer = ::Poll::Question::Answer.new(answer_params) @answer = @question.answers.new(answer_params)
@question = @answer.question
if @answer.save if @answer.save
redirect_to admin_question_path(@question), redirect_to admin_question_path(@question),
@@ -30,7 +29,7 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
def update def update
if @answer.update(answer_params) if @answer.update(answer_params)
redirect_to admin_question_path(@answer.question), redirect_to admin_question_path(@question),
notice: t("flash.actions.save_changes.notice") notice: t("flash.actions.save_changes.notice")
else else
render :edit render :edit