Module: ActiveAdmin::ViewHelpers::BreadcrumbHelper

Included in:
ActiveAdmin::ViewHelpers
Defined in:
lib/active_admin/view_helpers/breadcrumb_helper.rb

Instance Method Summary collapse

Instance Method Details

Returns an array of links to use in a breadcrumb



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_admin/view_helpers/breadcrumb_helper.rb', line 6

def breadcrumb_links(path = request.path)
  parts = path[1..-1].split('/') # remove leading "/" and split up the URL
  parts.pop                      # remove last since it's used as the page title

  parts.each_with_index.map do |part, index|
    # 1. try using `display_name` if we can locate a DB object
    # 2. try using the model name translation
    # 3. default to calling `titlecase` on the URL fragment
    if part =~ /\A(\d+|[a-f0-9]{24})\z/ && parts[index-1]
      config = active_admin_config.belongs_to_config.try(:target) || active_admin_config
      name   = display_name config.find_resource(part)
    end
    name ||= I18n.t "activerecord.models.#{part.singularize}", :count => 1.1, :default => part.titlecase

    link_to name, '/' + parts[0..index].join('/')
  end
end