Conversation
| class TestPassagesController < ApplicationController | ||
| before_action :authenticate_user! | ||
| before_action :set_test_passage, only: %i[ show result update ] | ||
| before_action :check_timer, only: [ :update ] |
There was a problem hiding this comment.
Опять с отступами м/у скобок бардак. Используй рубокоп.
|
|
||
| def check_timer | ||
| @test_passage = TestPassage.find(params[:id]) | ||
| if @test_passage.time_over? |
There was a problem hiding this comment.
Проверка времени это часть бизнес логики. Размазывать эту логику м/у контроллером и моделью плохая идея. Тем более уже есть метод отвечающий за завершение теста. Стоит доработать его.
app/javascript/utilities/timer.js
Outdated
|
|
||
| const redirectUrl = timerElement.dataset.timeoutUrl; | ||
| if (redirectUrl && redirectUrl !== 'undefined') { | ||
| window.location.href = redirectUrl; |
There was a problem hiding this comment.
Тут правильней и проще будет просто сабмитеть форму.
| created_at + (test.timer * 60) if test.timer.present? | ||
| end | ||
| def remaining_time | ||
| return unless timer_enabled? |
| flash[:alert] = t("test_passages.times_up") | ||
|
|
||
| redirect_to result_test_passage_path(@test_passage) | ||
| elsif @test_passage.question_any?(params) |
There was a problem hiding this comment.
если нет вопросов, значит тест завершился. А для этого есть уже подходящий метод #completed? который просто должен отвечать завершился ли тест. И не важно закончились вопросы и время. А сейчас получается что логику завершения теста не много размазали по коду
|
|
||
| if @test_passage.time_over? | ||
| flash[:alert] = t("test_passages.times_up") | ||
|
|
There was a problem hiding this comment.
внутри if код разделяют отступами
if @test_passage.time_over?
flash[:alert] = t("test_passages.times_up")
elsif
@test_pass...
end
No description provided.