Module: BreadcrumbHelper::Main

Defined in:
lib/breadcrumb_helper/main.rb

Overview

Contains the core code driver for breadcrumbs.

Instance Method Summary collapse

Instance Method Details

#add_breadcrumb(name:, path: nil) ⇒ Object

The method to add a breadcrumb item. Add more methods to the helper to modify breadcrumb items.



8
9
10
# File 'lib/breadcrumb_helper/main.rb', line 8

def add_breadcrumb(name:, path: nil)
  _breadcrumb_items << { name: name, path: path }
end

Copy of breadcrumb items to prevent modification.



13
14
15
# File 'lib/breadcrumb_helper/main.rb', line 13

def breadcrumb_items
  _breadcrumb_items.dup.freeze
end

#render_breadcrumb_itemsObject

Render the items to view as a string and html_safe on. Expected to find the partial in various locations thanks to Rails rendering.



19
20
21
22
23
24
25
26
# File 'lib/breadcrumb_helper/main.rb', line 19

def render_breadcrumb_items
  begin
    try("#{action_name}_breadcrumbs")
  rescue NoMethodError
    Rails.logger.warn("An error occurred in #{action_name}_breadcrumbs from #{controller_namespace}.")
  end
  render('breadcrumb_items', items: breadcrumb_items)
end