Rails: How to change the title of a page?

前端 未结 15 1291
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  自闭症患者
    2020-11-30 17:25

    Here's a simple option that I like to use

    In your layout

    
      <%= @title %>
    
    

    And at the top of your page template (first line)

    <% @title="Home" %>
    

    Because of the way the layout and page templates are parsed the @title="Home" is evaluated before the layout is rendered.

提交回复
热议问题