Skip to content

Conversation

@supronva-github
Copy link
Owner

No description provided.

timeLeft -= 1
} else {
clearInterval(countdownInterval)
var domain = window.location.protocol + '//' + window.location.host

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше нажать на сабмит, вместо редиректа

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сделал через сабмит

@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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем так сложно? сделай метод в test_passages который возвращает оставшееся время и передавай это значение во вьюху

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переделал, хотел вспомнить как сессии работают)

Comment on lines 3 to 4
before_action :get_end_time, only: %i[update result show]
before_action :check_end_time, only: %i[update]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сложная и ненужная логика. высчитывай в прохождении сколько осталось времени

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а проверять остаток можно в методе update. там же где проверка завершение теста

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переделал
Но я хз как мне учесть что пользователь вручную может обновить страницу и таймер скинется
через аякс запросы?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему он скинется? ты ведь выводишь остаток времени на вьюху. и этот остаток времени парсишь.


private

def check_timer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не надо этого. добавь в if @test_passage.completed? проверку на таймер. пусть вся логика работает там. ты тут дубль пишешь

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants