SimpleBreadcrumbs
This gem provides a simple and flexible way to create breadcrumbs with Rails active record
models. Setting has_breadcrumb
on a model will enable a view method,
breadcrumb()
, which will show the links to the page and its parents in
a breadcrumb format.
Installation
Add this line to your application's Gemfile:
gem 'simple_breadcrumbs'
And then execute:
$ bundle
Usage
In your model:
class User < ActiveRecord::Base
has_breadcrumb :title => :username
end
To display a model as a child of another model, you state the parent
by using the :parent
parameter:
class UserProfile < ActiveRecord::Base
has_breadcrumb :parent => :user, :title => "Profile"
end
As can be seen here, has_breadcrumb
can accept a String
on the
:title
option, which is useful in the case where there is no field in
the model which would be suitable. The :parent
option however, must
take a Symbol
.
Breadcrumb links are displayed in a view by including the breadcrumb
erb tag.
For example in an erb view for creating a new user,
<h2 class="subtitle"><%= breadcrumb @user, 'New' %></h2>
will provide a link which includes the Index page and the controller action to which this page is related.
Other options allowed by the breadcrumb
method include
:forced_parent
, which links to a non-natural parent of the current
view page.
By default, breadcrumb
includes a link to the index of an object when only
one level exists.
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