Sha256: aee860ba6f6cca4656fd57f2f17dc999c852adacc92b5717c929e7d10d506c81

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

module ActiveAdmin
  module ViewHelpers
    module BreadcrumbHelper

      # Returns an array of links to use in a breadcrumb
      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]
            parent = active_admin_config.belongs_to_config.try :target
            config = parent && parent.resource_name.route_key == parts[index-1] ? parent : active_admin_config
            name   = display_name config.find_resource part
          end
          name ||= I18n.t "activerecord.models.#{part.singularize}", count: ::ActiveAdmin::Helpers::I18n::PLURAL_MANY_COUNT, default: part.titlecase

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

    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
active_administration-0.0.3 lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadministration-0.0.2 lib/active_admin/view_helpers/breadcrumb_helper.rb
active_administration-0.0.2 lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadministration-0.0.1 lib/active_admin/view_helpers/breadcrumb_helper.rb
active_administration-0.0.1 lib/active_admin/view_helpers/breadcrumb_helper.rb