ruby - Rails: How to change the title of a page? -
what best way create custom title pages in rails app without using plug-in?
in views this:
<% content_for :title, "title specific page" %> <!-- or --> <h1><%= content_for(:title, "title specific page") %></h1>
the following goes in layout file:
<head> <title><%= yield(:title) %></title> <!-- additional header tags here --> </head> <body> <!-- if pages contain headline tag, it's preferable put in layout file --> <h1><%= yield(:title) %></h1> </body>
it's possible encapsulate content_for
, yield(:title)
statements in helper methods (as others have suggested). however, in simple cases such 1 put necessary code directly specific views without custom helpers.
Comments
Post a Comment