<% content_for :title, "Title for specific page" %>
<!-- or -->
<h1><%= content_for(:title, "Title for specific page") %></h1>
布局文件中包含以下内容:
<head>
<title><%= yield(:title) %></title>
<!-- Additional header tags here -->
</head>
<body>
<!-- If all pages contain a headline tag, it's preferable to put that in the layout file too -->
<h1><%= yield(:title) %></h1>
</body>
def get_title
@action_title_name || case controller_name
when 'djs'
'Djs'
when 'photos'
'Photos'
when 'events'
'Various events'
when 'static'
'Info'
when 'club'
'My club'
when 'news'
'News'
when 'welcome'
'Welcome!'
else
'Other'
end
end
之后,可以从布局的 title 标记中调用 get _ title。通过在操作中定义@action _ title _ name 变量,可以为页面定义更具体的标题。