Module: Loaf::ControllerExtensions::InstanceMethods
- Defined in:
- lib/loaf/controller_extensions.rb
Overview
ClassMethods
Instance Method Summary collapse
-
#_breadcrumbs ⇒ Object
private
Collection of breadcrumbs.
-
#add_breadcrumbs(collection, field, options = {}) ⇒ Object
Add collection of nested breadcrumbs.
-
#breadcrumb(name, url, options = {}) ⇒ Object
(also: #add_breadcrumb)
Add breadcrumb in controller as instance method.
-
#clear_breadcrumbs ⇒ Object
Remove all current breadcrumbs.
Instance Method Details
#_breadcrumbs ⇒ Object
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 ||= [] 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 (collection, field, = {}) namespace = nil item_set = if _check_if_nested collection items = collection.pop namespace = collection items else collection end item_set.each do |item| item.send(field.to_sym), [ namespace, item ].flatten.compact end end |
#breadcrumb(name, url, options = {}) ⇒ Object Also known as:
Add breadcrumb in controller as instance method
70 71 72 |
# File 'lib/loaf/controller_extensions.rb', line 70 def (name, url, = {}) << Loaf::Crumb.new(name, url, ) end |
#clear_breadcrumbs ⇒ Object
Remove all current breadcrumbs
85 86 87 |
# File 'lib/loaf/controller_extensions.rb', line 85 def .clear end |