From 82833b3e42cff95e2306de61744c046a6b450f19 Mon Sep 17 00:00:00 2001 From: masyuko0222 Date: Tue, 16 Jul 2024 14:40:52 +0900 Subject: [PATCH] =?UTF-8?q?find=5Fpractice=E3=81=A8=E3=81=84=E3=81=86?= =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E5=AE=9A=E7=BE=A9=E3=82=92?= =?UTF-8?q?=E3=82=84=E3=82=81=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・2箇所の重複しかないため、DRYとしての意味が薄いため ・不要なメソッドを定義することで可読性が低くなってしまっていたため --- .../mentor/practices/submission_answer_controller.rb | 8 ++------ app/controllers/practices/submission_answer_controller.rb | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) 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