Module: RailsBreadcrumbs::ControllerAdditions

Extended by:
ActiveSupport::Concern
Defined in:
lib/rails_breadcrumbs/controller_additions.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_breadcrumb_with_parent(object, path, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rails_breadcrumbs/controller_additions.rb', line 17

def add_breadcrumb_with_parent(object, path, options={})
  return unless object.present?
  options = ::RailsBreadcrumbs.options.merge(options)
  if defined?(Ancestry) && Ancestry::InstanceMethods.instance_methods.include?(:path)
    object.path.each do |element|
      make_url_and_add_breadcrumb(element, path, options)
    end
  elsif object.parent.present?
    [object.parent, object].each do |element|
      make_url_and_add_breadcrumb(element, path, options)
    end
  else
    make_url_and_add_breadcrumb(object, path, options)
  end
end

#add_breadcrumbs_by_path(names = {}, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rails_breadcrumbs/controller_additions.rb', line 33

def add_breadcrumbs_by_path(names = {}, options = {})
  options = ::RailsBreadcrumbs.options.merge(options)
  path_parts = controller_path.split('/')
  path_parts.each do |segment|
    link_name = segment.sub('_', ' ').camelcase
    link_name = names[segment] if names.has_key?(segment)
    name = I18n.t options[:locale_root] + segment, :default => link_name
    if segment != path_parts.last
      route = nil
      path_parts.each do |temp|
        route = (route.nil? ? temp: route +'_'+ temp)
        break if temp == segment
      end
      link = send(route + '_path')
    else
      link = request.path
    end
    add_breadcrumb(name, link)
  end
end

#add_breadcrumbs_with_action_by_path(names = {}, options = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rails_breadcrumbs/controller_additions.rb', line 54

def add_breadcrumbs_with_action_by_path(names = {}, options = {})
  options = ::RailsBreadcrumbs.options.merge(options)
  path_parts = controller_path.split('/') << action_name
  path_parts.each do |segment|
    link_name = segment.sub('_', ' ').camelcase
    link_name = names[segment] if names.has_key?(segment)
    name = I18n.t options[:locale_root] + segment, :default => link_name
    if segment != path_parts.last
      route = nil
      path_parts.each do |temp|
        route = (route.nil? ? temp: route +'_'+ temp)
        break if temp == segment
      end
      link = send(route + '_path')
    else
      link = request.path
    end
    add_breadcrumb(name, link)
  end
end