Module: ShowBreadcrumb
- Defined in:
- lib/has_breadcrumb/show_breadcrumb.rb
Instance Method Summary collapse
-
#breadcrumb(obj, action = nil, options = {}) ⇒ Object
View helper to generate breadcrumbs.
-
#collect_crumbs(obj, crumbs = []) ⇒ Object
Recursive function to lookup through parent breadcrumbs.
Instance Method Details
#breadcrumb(obj, action = nil, options = {}) ⇒ Object
View helper to generate breadcrumbs
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/has_breadcrumb/show_breadcrumb.rb', line 10 def (obj, action = nil, = {}) crumb_html = "" crumbs = collect_crumbs(obj) if .has_key?(:forced_parent) crumb_link = url_for :controller => [:forced_parent].class.to_s.underscore.pluralize, :action => "show", :id => [:forced_parent].id crumb_html = link_to [:forced_parent]., crumb_link elsif crumbs.length == 1 crumb_link = url_for :controller => obj.class.to_s.underscore.pluralize crumb_html = link_to obj.class.model_name.human.pluralize, crumb_link end crumbs.reverse.each do |crumb_obj| unless crumb_obj.id.nil? crumb_html += ' > ' if crumb_html.length > 0 crumb_link = url_for :controller => crumb_obj.class.to_s.underscore.pluralize, :action => "show", :id => crumb_obj.id crumb_html += link_to crumb_obj., crumb_link end end crumb_html += ' > ' + action + ' ' + obj.class.model_name.human.titleize if !action.nil? crumb_html.html_safe end |
#collect_crumbs(obj, crumbs = []) ⇒ Object
Recursive function to lookup through parent breadcrumbs
3 4 5 6 7 |
# File 'lib/has_breadcrumb/show_breadcrumb.rb', line 3 def collect_crumbs(obj, crumbs=[]) crumbs << obj crumbs = collect_crumbs(obj., crumbs) unless obj..nil? crumbs end |