Automatically add breadcrumbs to each page by using locales and gem breadcrumbs_on_rails
.
Installation
Add this line to your application's Gemfile:
gem 'auto_breadcrumbs'
And then execute:
$ bundle
To generate locale file run:
$ rails g auto_breadcrumbs:install
Usage
- Include
auto_breadcrumbs
in your controller:
class ApplicationController < ActionController::Base
include AutoBreadcrumbs
...
end
- Fill your locale file:
en:
auto_breadcrumbs:
root: 'Home'
actions:
new: 'New'
show: 'Show'
edit: 'Edit'
controllers:
users:
index: 'Users'
edit: 'Settings'
sync: 'Synchronization'
...
- Use helper method to show breadcrumbs in your view file:
<body>
<%= render_breadcrumbs %>
</body>
For example, if you go to /users/1/edit
it will show breadcrums like Home / Users / Settings
.
In case when translations are absent it will try to build breadcrumbs automatically depending on resource and action names.
For example, if you visit /countries/new
it will show breadcrums Home / Countries / New
.
You can also use helper methods resource_translation
and action_translation
like this:
<!DOCTYPE html>
<html>
<head>
<title><%= [resource_translation, action_translation].compact.join(' | ') %></title>
</head>
</html>
Customization
For more information about customization of breadcrumbs visit breadcrumbs_on_rails.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request