Sha256: fc503c4c10e9b1b36fdcfb994e83042c3f97cd831e25c2998f7184b5b4cc0600

Contents?: true

Size: 1.3 KB

Versions: 26

Compression:

Stored size: 1.3 KB

Contents

module ActiveAdmin
  module ViewHelpers
    module BreadcrumbHelper

      # Returns an array of links to use in a breadcrumb
      def breadcrumb_links(path = request.path)
        # remove leading "/" and split up the URL
        # and remove last since it's used as the page title
        parts = path.split('/').select(&:present?)[0..-2]

        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

          # Don't create a link if the resource's show action is disabled
          if !config || config.defined_actions.include?(:show)
            link_to name, '/' + parts[0..index].join('/')
          else
            name
          end
        end
      end

    end
  end
end

Version data entries

26 entries across 26 versions & 4 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/breadcrumb_helper.rb
yousty-activeadmin-1.0.17.pre lib/active_admin/view_helpers/breadcrumb_helper.rb
yousty-activeadmin-1.0.16.pre lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/breadcrumb_helper.rb
yousty-activeadmin-1.0.15.pre lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin-1.0.0.pre5 lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin-orac-1.0.0.pre4 lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin-orac-1.0.0 lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin-orac-1.0.0.pre.orac lib/active_admin/view_helpers/breadcrumb_helper.rb
yousty-activeadmin-1.0.14.pre lib/active_admin/view_helpers/breadcrumb_helper.rb
yousty-activeadmin-1.0.13.pre lib/active_admin/view_helpers/breadcrumb_helper.rb
yousty-activeadmin-1.0.12.pre lib/active_admin/view_helpers/breadcrumb_helper.rb
yousty-activeadmin-1.0.11.pre lib/active_admin/view_helpers/breadcrumb_helper.rb
yousty-activeadmin-1.0.10.pre lib/active_admin/view_helpers/breadcrumb_helper.rb
yousty-activeadmin-1.0.9.pre lib/active_admin/view_helpers/breadcrumb_helper.rb
yousty-activeadmin-1.0.8.pre lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin-1.0.0.pre4 lib/active_admin/view_helpers/breadcrumb_helper.rb