Rails: How to change the title of a page?

前端 未结 15 1306
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 17:08

What is the best way to create a custom title for pages in a Rails app without using a plug-in?

15条回答
  •  Happy的楠姐
    2020-11-30 17:43

    This simple approach sets a default title, but also let you override it whenever you please.

    In app/views/layouts/application.html.erb:

    <%= yield(:title) || 'my default title' %>
    

    And to override that default, place this in any view you like

    <% content_for :title, "some new title" %>
    

提交回复
热议问题