[RUBY] [Rails] About the Punk List function


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


Describe the gem "gretel" in the "Gemfile"


gem 'gretel'

Install it.

bundle install

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

rails g gretel:install


Edit the configuration file.


# 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

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

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

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

view file

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

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


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


<% breadcrumb :pics %>


<% breadcrumb :advises %>

The output looks like this.

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


<% breadcrumb :new_advise %>

The output looks like this.

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


<% breadcrumb :show_advise, @advise %>

The output looks like this.

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

It was displayed! !! : sparkles:


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! !!


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


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