From 861c1f942f50212f33c61635f5d305bc7c647902 Mon Sep 17 00:00:00 2001 From: Colby Swandale Date: Wed, 18 Aug 2021 20:53:17 +1000 Subject: [PATCH] Dont link to objects in the sidebar which do not exist --- app/controllers/application_controller.rb | 8 ++++++++ app/views/objects/_sidebar.html.slim | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 982166bea..e084d75de 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -45,6 +45,14 @@ def home_path end helper_method :home_path + def object_exists?(klass) + path = klass.is_a?(RubyObject) ? klass.id : RubyObject.id_from_path(klass) + !!RubyObjectRepository.repository_for_version(ruby_version).find(path) + rescue Elasticsearch::Persistence::Repository::DocumentNotFound + false + end + helper_method :object_exists? + def skip_session request.session_options[:skip] = true end diff --git a/app/views/objects/_sidebar.html.slim b/app/views/objects/_sidebar.html.slim index 34ff656ce..103603404 100644 --- a/app/views/objects/_sidebar.html.slim +++ b/app/views/objects/_sidebar.html.slim @@ -5,7 +5,7 @@ = render "objects/sidebar/section/link", additional_classes: "font-mono text-sm", title: @object.superclass.constant, - href: object_path(object: @object.superclass.path) + href: object_exists?(@object.superclass) ? object_path(object: @object.superclass.path) : "#" - unless @object.included_modules.empty? = render "objects/sidebar/section", title: 'Included Modules' do ul class="font-mono text-sm" @@ -13,7 +13,7 @@ li = render "objects/sidebar/section/link", title: included_module.constant, - href: object_path(object: included_module.path) + href: object_exists?(included_module) ? object_path(object: included_module.path) : "#" - unless @object.ruby_constants.empty? = render "objects/sidebar/section", title: 'Constants' do ul class="font-mono text-sm" @@ -45,7 +45,7 @@ div class="hidden lg:block w-1/4" = render "objects/sidebar/section/link", additional_classes: "font-mono text-sm", title: @object.superclass.constant, - href: object_path(object: @object.superclass.path) + href: object_exists?(@object.superclass) ? object_path(object: @object.superclass.path) : "#" - unless @object.included_modules.empty? = render "objects/sidebar/section", title: 'Included Modules' do ul class="font-mono text-sm" @@ -53,7 +53,7 @@ div class="hidden lg:block w-1/4" li = render "objects/sidebar/section/link", title: included_module.constant, - href: object_path(object: included_module.path) + href: object_exists?(included_module) ? object_path(object: included_module.path) : "#" - unless @object.ruby_constants.empty? = render "objects/sidebar/section", title: 'Constants' do ul class="font-mono text-sm"