diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 5713ea99a..1d4dd4982 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -2,17 +2,16 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController include Translatable include DocumentAttributes - before_action :load_answer, only: [:show, :edit, :update, :documents] - load_and_authorize_resource :question, class: "::Poll::Question" + load_resource class: "::Poll::Question::Answer", + through: :question, + through_association: :question_answers, + except: :documents def new - @answer = @question.answers.new end def create - @answer = @question.answers.new(answer_params) - if @answer.save redirect_to admin_question_path(@question), notice: t("flash.actions.create.poll_question_answer") @@ -37,6 +36,7 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController end def documents + @answer = ::Poll::Question::Answer.find(params[:answer_id]) @documents = @answer.documents render "admin/poll/questions/answers/documents" @@ -54,16 +54,11 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController end def allowed_params - attributes = [:title, :description, :given_order, :question_id, - documents_attributes: document_attributes] + attributes = [:title, :description, :given_order, documents_attributes: document_attributes] [*attributes, translation_params(Poll::Question::Answer)] end - def load_answer - @answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id]) - end - def resource load_answer unless @answer @answer diff --git a/app/views/admin/poll/questions/answers/_form.html.erb b/app/views/admin/poll/questions/answers/_form.html.erb index 53eceae17..ef32b93e5 100644 --- a/app/views/admin/poll/questions/answers/_form.html.erb +++ b/app/views/admin/poll/questions/answers/_form.html.erb @@ -7,8 +7,6 @@ <%= f.hidden_field :given_order, value: @answer.persisted? ? @answer.given_order : @answer.class.last_position(@answer.question_id || @question.id) + 1 %> - <%= f.hidden_field :question_id, value: @answer.question_id || @question.id %> -