diff --git a/app/controllers/mentor/practices/submission_answer_controller.rb b/app/controllers/mentor/practices/submission_answer_controller.rb index c3c270019e3..9988a7daa3f 100644 --- a/app/controllers/mentor/practices/submission_answer_controller.rb +++ b/app/controllers/mentor/practices/submission_answer_controller.rb @@ -5,7 +5,7 @@ class Mentor::Practices::SubmissionAnswerController < ApplicationController before_action :set_submission_answer, only: %i[edit update] def new - @practice = find_practice + @practice = Practice.find(params[:practice_id]) @submission_answer = @practice.build_submission_answer end @@ -14,7 +14,7 @@ def edit end def create - @practice = find_practice + @practice = Practice.find(params[:practice_id]) @submission_answer = @practice.build_submission_answer(submission_answer_params) if @submission_answer.save redirect_to practice_submission_answer_url, notice: '模範解答を作成しました。' @@ -38,10 +38,6 @@ def set_submission_answer @submission_answer = SubmissionAnswer.find_by(practice_id: params[:practice_id]) end - def find_practice - Practice.find(params[:practice_id]) - end - def submission_answer_params params.require(:submission_answer).permit(:description) end diff --git a/app/controllers/practices/submission_answer_controller.rb b/app/controllers/practices/submission_answer_controller.rb index 73adde391a1..98812b69107 100644 --- a/app/controllers/practices/submission_answer_controller.rb +++ b/app/controllers/practices/submission_answer_controller.rb @@ -4,21 +4,17 @@ class Practices::SubmissionAnswerController < ApplicationController before_action :check_permission!, only: %i[show] def show - @practice = find_practice + @practice = Practice.find(params[:practice_id]) @submission_answer = @practice.submission_answer end private def check_permission! - practice = find_practice + practice = Practice.find(params[:practice_id]) submission_answer = practice.submission_answer || SubmissionAnswer.new(practice:) return if policy(submission_answer).show? redirect_to practice_path(practice), alert: 'プラクティスを修了するまで模範解答は見れません。' end - - def find_practice - Practice.find(params[:practice_id]) - end end