Rails: How to change the title of a page?

前端 未结 15 1336
没有蜡笔的小新
没有蜡笔的小新 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:39

    approach for page titling using content_for method and a partial

    1 . partial name : _page_title.html.erb

    <%content_for :page_title do %>
     <%=title%>
    <%end%>
    

    2 . Usage in application.html.erb inside title tag

       <%=yield :page_title %>
    

    3 . Usage in respective *.html.erb excluding application.html.erb Just stick this in any .html.erb and supply title of the page

        e.g : inside index.html.erb
    
        <%=render '_page_title', title: 'title_of_page'%>
    

提交回复
热议问题