Rails Breadcrumbs
module Breadcrumbs
def self.included(base)
base.extend ClassMethods
end
def add_breadcrumb(name, path)
@breadcrumbs ||= []
@breadcrumbs << Breadcrumb.new(name, path)
end
module ClassMethods
def add_breadcrumb(name, path = nil, options = {})
before_filter options do |controller|
path = controller.send(path) if path.is_a? Symbol
controller.send(:add_breadcrumb, name, path)
end
end
end
class Breadcrumb
attr_reader :name, :path
def initialize(name, path)
@name = name
@path = path
end
end
end
Written by Nick Larson
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#