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:
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:
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
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: "›" %></p>
ruby:pics/index.html.erb
<% breadcrumb :pics %>
ruby:advise/index.html.erb
<% breadcrumb :advises %>
The output looks like this.
ruby:advises/new.html.erb
<% breadcrumb :new_advise %>
The output looks like this.
ruby:advises/show.html.erb
<% breadcrumb :show_advise, @advise %>
The output looks like this.
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
omake:relaxed:
Recommended Posts