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.59 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.58 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.57 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.56 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.50 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb
lalala-4.0.0.dev.46 vendor/deps/active_admin/lib/active_admin/view_helpers/breadcrumb_helper.rb