-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson 18 2 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Lesson 18 2 #18
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше нажать на сабмит, вместо редиректа
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
сделал через сабмит
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем так сложно? сделай метод в test_passages который возвращает оставшееся время и передавай это значение во вьюху
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
переделал, хотел вспомнить как сессии работают)
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
сложная и ненужная логика. высчитывай в прохождении сколько осталось времени
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а проверять остаток можно в методе update. там же где проверка завершение теста
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
переделал
Но я хз как мне учесть что пользователь вручную может обновить страницу и таймер скинется
через аякс запросы?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему он скинется? ты ведь выводишь остаток времени на вьюху. и этот остаток времени парсишь.
|
|
||
| private | ||
|
|
||
| def check_timer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не надо этого. добавь в if @test_passage.completed? проверку на таймер. пусть вся логика работает там. ты тут дубль пишешь
No description provided.