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 %> -
<%= f.translatable_fields do |translations_form| %>
diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index 4c0396849..7a94fd8e6 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -9,7 +9,7 @@
<%= form_for(Poll::Question::Answer.new, - url: admin_answer_path(@answer), + url: admin_question_answer_path(@answer.question, @answer), method: :put) do |f| %> <%= render "shared/errors", resource: @answer %> diff --git a/app/views/admin/poll/questions/answers/edit.html.erb b/app/views/admin/poll/questions/answers/edit.html.erb index 46a8784cc..def21279d 100644 --- a/app/views/admin/poll/questions/answers/edit.html.erb +++ b/app/views/admin/poll/questions/answers/edit.html.erb @@ -10,5 +10,5 @@
- <%= render "form", form_url: admin_answer_path(@answer) %> + <%= render "form", form_url: admin_question_answer_path(@question, @answer) %>
diff --git a/app/views/admin/poll/questions/answers/show.html.erb b/app/views/admin/poll/questions/answers/show.html.erb index 8244687b2..00bc72b02 100644 --- a/app/views/admin/poll/questions/answers/show.html.erb +++ b/app/views/admin/poll/questions/answers/show.html.erb @@ -1,6 +1,6 @@ <%= back_link_to %> -<%= link_to t("admin.answers.show.edit"), edit_admin_answer_path(@answer), +<%= link_to t("admin.answers.show.edit"), edit_admin_question_answer_path(@answer.question, @answer), class: "button hollow float-right" %>