Skip to content

Don't link to objects in the sidebar which do not exist #857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/views/objects/_sidebar.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
= 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"
- @object.included_modules.each do |included_module|
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"
Expand Down Expand Up @@ -45,15 +45,15 @@ 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"
- @object.included_modules.each do |included_module|
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"
Expand Down