Skip to content

Commit 5183f45

Browse files
committed
Try up to 5 times to create a serendip question to ask
1 parent 270d32e commit 5183f45

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

app/controllers/main_controller.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
class MainController < ApplicationController
44
layout 'landing', only: [:index, :about_notebook]
55

6+
class RetryMe < StandardError; end
7+
68
def index
79
redirect_to :dashboard if user_signed_in?
810
end
@@ -16,7 +18,16 @@ def comingsoon
1618
def dashboard
1719
return redirect_to new_user_session_path unless user_signed_in?
1820

19-
@content = current_user.content.values.flatten.sample
20-
@question = @content.question unless @content.nil?
21+
# Try up to 5 times to actually fetch a question
22+
attempts = 0
23+
24+
begin
25+
@content = current_user.content.values.flatten.sample
26+
@question = @content.question unless @content.nil?
27+
28+
raise RetryMe if @question.nil? || @question[:question].nil? # :(
29+
rescue RetryMe
30+
retry if attempts < 5
31+
end
2132
end
2233
end

0 commit comments

Comments
 (0)