Skip to content

Instantly share code, notes, and snippets.

@andreferraro
Created July 8, 2010 15:26
Show Gist options
  • Save andreferraro/468150 to your computer and use it in GitHub Desktop.
Save andreferraro/468150 to your computer and use it in GitHub Desktop.
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
#BREADCRUMBS
before_filter :trail
def self.trail(&block)
# Controller-level trails become filters so they run inside the
# request/response cycle, where internationalization etc works.
# instance_exec means you can use path helpers.
before_filter {|controller| controller.instance_exec(controller.send(:trail), &block) }
end
# trail {|t| t << ['Backend', '/backend/'] }
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 { |crumb|
text, url = Array(crumb)
last_crumb = @crumbs.last
template.instance_eval {
link_to_unless((crumb == last_crumb || url.blank?), h(text), url) {|text| content_tag(:span, text) }
}
}.join(" &gt; ")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment