Sha256: e0011a6bb90cc6bcdf09fcf112e98d9b03e16c60dc2714cbce00bd2a96155ea1

Contents?: true

Size: 1.05 KB

Versions: 46

Compression:

Stored size: 1.05 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 URL path
        parts.pop unless params[:action] =~ /^create|update$/ # remove last if not create/update

        parts.each_with_index.map do |part, index|
          # If an object (users/23), look it up via ActiveRecord and capture its name.
          # If name is nil, look up the model translation, using `titlecase` as the backup.
          if part =~ /^\d|^[a-f0-9]{24}$/ && parent = parts[index-1]
            klass = parent.singularize.camelcase.constantize rescue nil
            obj   = klass.find_by_id(part) if klass
            name  = display_name(obj)      if obj
          end
          name ||= I18n.t "activerecord.models.#{part.singularize}", :count => 1.1, :default => part.titlecase

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

    end
  end
end

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
lalala-4.0.0.dev.141 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.128 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.126 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.125 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.124 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.123 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.118 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.116 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.114 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.113 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.111 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.109 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.107 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb