public
Last active — forked from henrik/application.html.erb

  • Download Gist
application.html.erb
HTML+ERB
1 2
You are here:
<%= trail.to_html(response) %>
application_controller.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
class ApplicationController < ActionController::Base
before_filter :trail
 
def self.trail(&block)
# Controller-level trails become filters so they run inside the
# request/response cycle, where internationalization etc works.
before_filter {|controller| block.call(controller.send(:trail)) }
end
 
trail {|t| t << ['Home', '/'] }
 
protected
 
def trail
@breadcrumb_trail ||= BreadcrumbTrail.new
end
helper_method :trail
 
class BreadcrumbTrail
def initialize
@crumbs = []
end
 
def <<(crumb)
@crumbs << crumb
end
 
def append(crumbs)
@crumbs += crumbs
end
 
def to_html(response)
template = response.template
@crumbs.map {|text, url| template.instance_eval {
link_to_unless_current(h(text), url)
} }.join(" &gt; ")
end
end
 
end
items/show.html.erb
HTML+ERB
1 2 3 4 5 6
<%
trail << ['Specific item from view', '/items/123']
# Note that since layouts are rendered after their child template,
# trails appended in a layout will currently come after those
# appended in the child templates.
%>
items_controller.rb
Ruby
1 2 3 4 5 6 7 8 9
class ItemsController < ApplicationController
 
trail {|t| t << ['Items', '/items'] }
 
def show
trail << ['Specific item from controller', '/items/123']
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.