0

How can I get the title of my page using Rails? content_for will set it, so is there a better way than to assign it to an instance variable?

1 Answer 1

1

If your'e using content_for to set it, you can simply use content_for to get it as well.

<% content_for :title, "My Title" %>

Some time later ... 
<title><%= content_for :title %></title>
...
<h1><%= content_for :title %></h1>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.