Class: SimpleAdmin::Breadcrumbs
- Inherits:
-
Object
- Object
- SimpleAdmin::Breadcrumbs
- Defined in:
- lib/simple_admin/breadcrumbs.rb
Class Method Summary collapse
-
.parse(path, action) ⇒ Object
Returns an array of links to use in a breadcrumb.
Class Method Details
.parse(path, action) ⇒ Object
Returns an array of links to use in a breadcrumb
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/simple_admin/breadcrumbs.rb', line 4 def self.parse(path, action) parts = path.gsub(/^\//, '').split('/') parts.pop unless %w{ create update }.include?(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 == "" crumbs << [name, "/" + parts[0..index].join('/')] end crumbs end |