diff --git a/app/components/polls/questions/options_component.html.erb b/app/components/polls/questions/options_component.html.erb index b687ed249..ae5d6f2a6 100644 --- a/app/components/polls/questions/options_component.html.erb +++ b/app/components/polls/questions/options_component.html.erb @@ -11,7 +11,7 @@ "aria-pressed": true %> <% else %> <%= button_to question_option.title, - answer_question_path(question, answer: question_option.title), + question_answers_path(question, answer: question_option.title), remote: true, title: t("poll_questions.show.vote_answer", answer: question_option.title), class: "button secondary hollow", diff --git a/app/controllers/polls/answers_controller.rb b/app/controllers/polls/answers_controller.rb index 174cc673c..fc75620ec 100644 --- a/app/controllers/polls/answers_controller.rb +++ b/app/controllers/polls/answers_controller.rb @@ -2,7 +2,24 @@ class Polls::AnswersController < ApplicationController load_and_authorize_resource :question, class: "::Poll::Question" load_and_authorize_resource :answer, class: "::Poll::Answer", through: :question, - through_association: :answers + through_association: :answers, + only: :destroy + + def create + authorize! :answer, @question + + answer = @question.find_or_initialize_user_answer(current_user, params[:answer]) + answer.save_and_record_voter_participation + + respond_to do |format| + format.html do + redirect_to request.referer + end + format.js do + render :show + end + end + end def destroy @answer.destroy_and_remove_voter_participation @@ -12,7 +29,7 @@ class Polls::AnswersController < ApplicationController redirect_to request.referer end format.js do - render "polls/questions/options" + render :show end end end diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb deleted file mode 100644 index 07810bbfc..000000000 --- a/app/controllers/polls/questions_controller.rb +++ /dev/null @@ -1,17 +0,0 @@ -class Polls::QuestionsController < ApplicationController - load_and_authorize_resource :question, class: "Poll::Question" - - def answer - answer = @question.find_or_initialize_user_answer(current_user, params[:answer]) - answer.save_and_record_voter_participation - - respond_to do |format| - format.html do - redirect_to request.referer - end - format.js do - render :options - end - end - end -end diff --git a/app/views/polls/questions/options.js.erb b/app/views/polls/answers/show.js.erb similarity index 100% rename from app/views/polls/questions/options.js.erb rename to app/views/polls/answers/show.js.erb diff --git a/config/routes/poll.rb b/config/routes/poll.rb index d33e75923..f5be6b301 100644 --- a/config/routes/poll.rb +++ b/config/routes/poll.rb @@ -5,8 +5,7 @@ resources :polls, only: [:show, :index] do end resources :questions, controller: "polls/questions", shallow: true, only: [] do - post :answer, on: :member - resources :answers, controller: "polls/answers", only: :destroy, shallow: false + resources :answers, controller: "polls/answers", only: [:create, :destroy], shallow: false end end