gretelを使ったパンくずリストの作成手順

gem gretelを用いてパンくずリストを作成します
例として、記事編集画面(article/:id/edit)にアクセスした際に
Home > 記事 > 記事編集
というパンくずリストが表示される様にします。

1. gemをインストールする

Gemfile
gem 'gretel'
$ bundle install

2. パンくずの設定

設定ファイルを作成する

$ rails g  gretel:install

生成されたファイルを編集する

config/bredcrumb.rb
crumb :root do
  link 'Home', root_path
end

crumb :articles do
  link '記事', articles_path
  parent :root
end

crumb :edit_articles do |article|
  link '記事編集', edit_article_path(article)
  parent :article
end

3. viewの編集

共通レイアウトを編集してパンくずを表示する場所を決める

app/views/layout/application.html.erb
<!doctype html>
<html>
  <head>

  </head>
  <body>
    <%= breadcrumbs %>
    <%= yield %>
  </body>
</html> 

viewファイルに合わせて設定したcrumbを当てていきます

app/views/article/index.html.erb
<% breadcrumb :article %>
app/views/articles/edit.html.erb
<% breadcrumb :edit_articles, @article %>