・ Ruby: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ OS: macOS Catalina
The following has been implemented.
application_helper.rb
module ApplicationHelper
#Postscript
def full_title(page_title = '')
base_title = "Bookers"
if page_title.empty?
base_title
else
"#{ page_title } | #{ base_title }"
end
end
end
** ◎ Set the base title (app name, etc.) and assign it to a variable. ** **
base_title = "Bookers"
** ◎ If the title of each page received as an argument is empty, only the base title is displayed. ** **
if page_title.empty?
base_title
** ◎ If the title of each page received as an argument exists, both titles are displayed. ** **
else
"#{ page_title } | #{ base_title }"
If page_title
is" book list ", it will be displayed as book list | Bookers
.
slim:application.html.slim
/Change before
title
| Bookers
/After change
title
= full_title(yield(:title))
As an example, set the title of books / index.html.slim
.
slim:books/index.html.slim
/Postscript
= provide(:title, 'Book list')
Recommended Posts