Breadcrumbs
Breadcrumbs is a simple plugin that adds a breadcrumbs
object to controllers
and views.
Instalation
Just run gem install breadcrumbs
. Or add gem "breadcrumbs"
to your Gemfile.
Usage
On your controller (optional):
class ApplicationController < ActionController::Base
before_filter :add_initial_breadcrumbs
private
def
.add "Home", root_path
end
end
class ThingsController < ApplicationController
def index
.add "Things", things_path
end
end
You don't need to provide an URL; in that case, a span will be generated instead of a link:
.add "Some page"
You can set additional HTML attributes if you need to:
.add "Home", root_path, id: "home", title: "Go to the home page"
On your view (possibly application.html.erb):
<%= breadcrumbs.render %>
You can render as ordered list.
<%= breadcrumbs.render(format: :ordered_list) %>
You can render as inline links.
<%= breadcrumbs.render(format: :inline) %>
You can set your own separator:
<p>
You are here: <%= breadcrumbs.render(format: :inline, separator: "|") %>
</p>
You can also define your own formatter. Just create a class that implements a
render
instance method and you're good to go.
class Breadcrumbs::Render::Dl
def render
# return breadcrumbs wrapped in a <dl> tag
end
end
To use your new format, just provide the :format
option.
.render(format: :dl)
I18n
Breadcrumbs is integrated with I18n. You can set translations like:
en:
breadcrumbs:
home: "Home"
And then you just call
.add :home
In fact, you can provide any scope you want.
.add :"titles.home"
If you don't want to translate a label, just pass the option :i18n
as false
.
.add :home, nil, i18n: false
Maintainer
Contributors
Contributing
For more details about how to contribute, please read https://github.com/fnando/breadcrumbs/blob/main/CONTRIBUTING.md.
License
The gem is available as open source under the terms of the MIT License. A copy of the license can be found at https://github.com/fnando/breadcrumbs/blob/main/LICENSE.md.
Code of Conduct
Everyone interacting in the breadcrumbs project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.