Conversation
app/javascript/utilities/timer.js
Outdated
| timeLeft -= 1 | ||
| } else { | ||
| clearInterval(countdownInterval) | ||
| var domain = window.location.protocol + '//' + window.location.host |
There was a problem hiding this comment.
лучше нажать на сабмит, вместо редиректа
There was a problem hiding this comment.
сделал через сабмит
app/controllers/tests_controller.rb
Outdated
| @test = Test.find(params[:id]) | ||
| current_user.tests.push(@test) | ||
| redirect_to current_user.test_passage(@test) | ||
| session[:"end_time_#{TestPassage.last.id}"] = Time.now + @test.duration_time.minute if @test.duration_time.present? |
There was a problem hiding this comment.
зачем так сложно? сделай метод в test_passages который возвращает оставшееся время и передавай это значение во вьюху
There was a problem hiding this comment.
переделал, хотел вспомнить как сессии работают)
| before_action :get_end_time, only: %i[update result show] | ||
| before_action :check_end_time, only: %i[update] |
There was a problem hiding this comment.
сложная и ненужная логика. высчитывай в прохождении сколько осталось времени
There was a problem hiding this comment.
а проверять остаток можно в методе update. там же где проверка завершение теста
There was a problem hiding this comment.
переделал
Но я хз как мне учесть что пользователь вручную может обновить страницу и таймер скинется
через аякс запросы?
There was a problem hiding this comment.
почему он скинется? ты ведь выводишь остаток времени на вьюху. и этот остаток времени парсишь.
|
|
||
| private | ||
|
|
||
| def check_timer |
There was a problem hiding this comment.
не надо этого. добавь в if @test_passage.completed? проверку на таймер. пусть вся логика работает там. ты тут дубль пишешь
No description provided.