0
0

More than 1 year has passed since last update.

パンくずリストの作成 breadcrumbs

Posted at

導入

パンくずリストの導入にはgretelというgemが便利。

gem 'gretel'
% bundle install
% rails g gretel:install

上記のコマンドで、configディレクトリ直下にbreadcrumbs.rbが作成される。

パンくずリストの作成

例として、トップページ→投稿一覧→投稿詳細という階層のリストを作成する。

crumb :root do
 link "Top", root_path
end

crumb :post_index do
 link "投稿一覧", posts_path
 parent :root
end

crumb :post_show |post| do
 link "投稿詳細", post_path(post)
 parent :post_index
end

対象のviewファイルに下記のように記載する。

<% breadcrumb :post_index %>
<% breadcrumb :post_show, @post %>

作成イメージ

Image from Gyazo

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0