0

Following the guidance set out here: Rails: How to change the title of a page?

I am attempting to use: <h1><%= content_for(:title, "Title for specific page") %></h1>

While my page title does update successfully: <title>Title for specific page</title>

In my source code the <h1> tags are empty: <h1></h1>

Any ideas what I am doing incorrectly?

JoshuaESummers
  • 493
  • 2
  • 7
  • 24

1 Answers1

3

content_for isn't meant to render data 'in place', it returns nil. Instead, you can define your title in the controller and reuse it in view, for example:

@title = 'Title for specific page'

and have in your view:

<% content_for :title, @title %>
<h1><%= @title %></h1>
Marek Lipka
  • 50,622
  • 7
  • 87
  • 91