Sha256: 270d7a0bf4f9da71b807ebffb13f2fb6a4ebe0f4a90b5f4257d5635949921e78

Contents?: true

Size: 981 Bytes

Versions: 9

Compression:

Stored size: 981 Bytes

Contents

module ActiveAdmin
  module ViewHelpers
    module BreadcrumbHelper

			# Returns an array of links to use in a breadcrumb
			def breadcrumb_links(path = nil)
				path ||= request.fullpath
				parts = path.gsub(/^\//, '').split('/')
				parts.pop unless %w{ create update }.include?(params[:action])
				crumbs = []
				parts.each_with_index do |part, index|
					name = ""
					if part =~ /^\d/ && parent = parts[index - 1]
						begin
							parent_class = parent.singularize.camelcase.constantize
							obj = parent_class.find(part.to_i)
							name = obj.display_name if obj.respond_to?(:display_name)
						rescue
						end
					end
					name = part.titlecase if name == ""
					begin
						crumbs << link_to( I18n.translate!("activerecord.models.#{part.singularize}", :count => 2), "/" + parts[0..index].join('/'))
					rescue I18n::MissingTranslationData
						crumbs << link_to( name, "/" + parts[0..index].join('/'))
					end
				end
				crumbs
			end

    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
activeadmin-0.4.4 lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin-0.4.3 lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin-0.4.2 lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin-0.4.1 lib/active_admin/view_helpers/breadcrumb_helper.rb
activeadmin-0.4.0 lib/active_admin/view_helpers/breadcrumb_helper.rb
andrewroth_activeadmin-0.3.4.4 lib/active_admin/view_helpers/breadcrumb_helper.rb
andrewroth_activeadmin-0.3.4.3 lib/active_admin/view_helpers/breadcrumb_helper.rb
andrewroth_activeadmin-0.3.4.2 lib/active_admin/view_helpers/breadcrumb_helper.rb
andrewroth_activeadmin-0.3.4.1 lib/active_admin/view_helpers/breadcrumb_helper.rb