fix a potential 500 when a universe is prompted

This commit is contained in:
Andrew Brown 2018-10-17 12:31:09 -05:00
parent 6ca4bfe76c
commit f767fa50c2

View File

@ -83,10 +83,21 @@ class MainController < ApplicationController
def set_random_content
@activated_content_types.shuffle.each do |content_type|
if @universe_scope.present?
@content = content_type.constantize.where(user: current_user, universe: @universe_scope).sample
if content_type.downcase == "universe"
if @universe_scope.present?
# when we want to enable prompts for contributing universes we can remove the user:
# selector here, but we will need to verify the user has permission to see the universe
# when we do that, or else prompts could open leak
@content = content_type.constantize.where(user: current_user, id: @universe_scope.id).sample
else
@content = content_type.constantize.where(user: current_user).sample
end
else
@content = content_type.constantize.where(user: current_user).sample
if @universe_scope.present?
@content = content_type.constantize.where(user: current_user, universe: @universe_scope).sample
else
@content = content_type.constantize.where(user: current_user).sample
end
end
return if @content.present?