diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 4d4853a28..42ce9a2e8 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -22,9 +22,14 @@ def dashboard attempts = 0 begin - @content = current_user.content.values.flatten.sample - @question = @content.question unless @content.nil? + if @universe_scope.present? && attempts < 2 + content_pool = current_user.content_in_universe(@universe_scope).values.flatten + else + content_pool = current_user.content.values.flatten + end + @content = content_pool.sample + @question = @content.question unless @content.nil? raise RetryMe if @content.present? && (@question.nil? || @question[:question].nil?) # :( rescue RetryMe attempts += 1 diff --git a/app/models/concerns/has_content.rb b/app/models/concerns/has_content.rb index f49275cbb..52c9a8bb8 100644 --- a/app/models/concerns/has_content.rb +++ b/app/models/concerns/has_content.rb @@ -41,6 +41,21 @@ def content } end + def content_in_universe universe_id + { + characters: characters.in_universe(universe_id), + items: items.in_universe(universe_id), + locations: locations.in_universe(universe_id), + creatures: creatures.in_universe(universe_id), + races: races.in_universe(universe_id), + religions: religions.in_universe(universe_id), + magics: magics.in_universe(universe_id), + languages: languages.in_universe(universe_id), + scenes: scenes.in_universe(universe_id), + groups: groups.in_universe(universe_id) + } + end + def content_count [ characters.length,