[Rails] About the Punk List function

Introduction

This time I implemented and reviewed the Punks function so that I can implement it again soon

I would like to write it down.

I will implement it. : fire :: fire:

What is the Punks function?

It is a function that makes it easy to visually understand which page you are currently on.

In the story "Hansel and Gretel", Hansel and Gretel dropped the dust on the mark of the road they came while walking in the woods so as not to get lost, so it was a "punk waste function". It seems that the name of gem is "gretel".

It's cute: bread:

By the way, Hansel is a boy and Gretel is a girl. : couple:

[gem gretel] Details

Implementation

Describe the gem "gretel" in the "Gemfile"

Gemfile



gem 'gretel'

Install it.


bundle install

Entering this will generate a "breadcrumbs.rb" file under the "config" directory.


rails g gretel:install

config/breadcrumbs.rb

Edit the configuration file.

config/breadcrumbs.rb



# crumb "Current page (also described on the page to be displayed)" do
# link "Display name in the Punk list", "The path of the page you want to access"
# parent "Parent element page(Previous page)"


crumb :pics do
  link "Home", root_path
end

crumb :advises do 
  link "Consultation list", advises_path
  parent :pics
end

crumb :new_advise do 
  link "Consultation new post", new_advise_path
  parent :advises
end

crumb :show_advise do 
  link "Consultation details", advise_path
  parent :advises
end

view file

Use the optional "pretext" When you enter a character, that character is output.

Using "separator" If you enter " & rsaquo; ", ">" will be output.

ruby:application.html.erb



<p><%= breadcrumbs pretext: "You are here: ",
                                      separator: "&rsaquo;" %></p>

ruby:pics/index.html.erb



<% breadcrumb :pics %>

ruby:advise/index.html.erb



<% breadcrumb :advises %>

The output looks like this.

スクリーンショット 2021-01-17 11.24.09.png

ruby:advises/new.html.erb



<% breadcrumb :new_advise %>

The output looks like this.

スクリーンショット 2021-01-17 11.23.24.png

ruby:advises/show.html.erb



<% breadcrumb :show_advise, @advise %>

The output looks like this.

スクリーンショット 2021-01-17 11.22.50.png

It was displayed! !! : sparkles:

Summary

It took a while since I implemented the Punks function in the new file and show file for the first time. I was able to implement it safely! !!

It's convenient to know where you are.

There seem to be other options, so I would like to try different ones.

By the way

Here it is written like this. Forum: Is the breadcrumb trail above or below the page?

A follower asked Google's John Mueller on Twitter.

Mr. Mueller replied:

It doesn't matter where you install it.

For personal advice, I recommend adding user interface elements to your page to make them easier to use (otherwise it wouldn't make sense to add them). However, it depends on the site whether it is easy to use. And you are the one who knows the site best.

I see So today I want to end this! !!

reference

DoRuby: Create breadcrumb trail with gretel

virtualiment: How to use Gem gretel to display breadcrumb trails in Ruby on Rails

You can see the details from github. GitHub gretel

omake:relaxed:

Web knowledge to keep in mind: [Ruby on Rails] I will explain the app directory and config directory in an easy-to-understand manner!

Recommended Posts

[Rails] About the Punk List function
About the function double-java
about the where method (rails)
Rails ~ Understanding the message function ~
About the symbol <%%> in Rails erb
About Rails 6
[Rails] About implementation of like function
A note about the seed function of Ruby on Rails
About Rails routing
[Rails 6] Ranking function
[Rails] Category function
About the method
Rails follow function
[Rails] About ActiveJob ,!
About the package
About Rails controller
About List [Java]
About RSpec (Rails)
[Rails] Notification function
A note about the Rails and Vue process
Output about the method # 2
[Note] Rails error list
[Rails] I learned about the difference between resources and resources
[Rails] About migration files
[Rails 6] About main gems
Commentary: About the interface
About rails application server
About the asset pipeline
About rails kaminari pagination
About rails version specification
[Rails] Implement search function
About the ternary operator
[Rails] Implemented hashtag function
Let's understand the function!
[rails] tag ranking function
MEMO about Rails 6 series
About the length method
About Java Array List
About the Kernel module
[Rails] About Slim notation
Rails search function implementation
About the authenticate method.
Questions about implementing the Like feature (Ajax) in Rails
About the map method
About the ancestors method
[Output] About the database
[Rails 6] Rubocop warning list
[rails] About devise defaults
About the [ruby] operator
About the to_s method.
Master the [Rails] scope!
Rails: About partial templates
About rails strong parameters
[Beginner] About Rails Session
About the function of Spring Boot due to different versions
Delete all the contents of the list page [Ruby on Rails]
[Rails] Function to search and list products from multi-level categories
[Note] About the Fizz_Buzz problem (How Ruby on Rails works)
[Rails] How to display the list of posts by category
Implement application function in Rails
About specifying the JAXRS path