Module: Loaf::ControllerExtensions::InstanceMethods

Defined in:
lib/loaf/controller_extensions.rb

Overview

ClassMethods

Instance Method Summary collapse

Instance Method Details

#_breadcrumbsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Collection of breadcrumbs



78
79
80
# File 'lib/loaf/controller_extensions.rb', line 78

def _breadcrumbs
  @_breadcrumbs ||= []
end

#add_breadcrumbs(collection, field, options = {}) ⇒ Object

Add collection of nested breadcrumbs.

  • collection - required collection of object for iteration

  • field - required object attribute name



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/loaf/controller_extensions.rb', line 49

def add_breadcrumbs(collection, field, options = {})
  namespace = nil
  item_set = if _check_if_nested collection
     items = collection.pop
     namespace = collection
     items
  else
    collection
  end
  item_set.each do |item|
    add_breadcrumb item.send(field.to_sym), [ namespace, item ].flatten.compact
  end
end

Add breadcrumb in controller as instance method

Parameters:

  • name (String)
  • url (Object)


70
71
72
# File 'lib/loaf/controller_extensions.rb', line 70

def breadcrumb(name, url, options = {})
  _breadcrumbs << Loaf::Crumb.new(name, url, options)
end

#clear_breadcrumbsObject

Remove all current breadcrumbs



85
86
87
# File 'lib/loaf/controller_extensions.rb', line 85

def clear_breadcrumbs
  _breadcrumbs.clear
end