Rails sets the page title.

How to set the page title in some views and use the default title if it is not set?
I am using HAML. What is the right way to do this?

Now I like:

- content_for :title, "Title for specific page"

and in the layout:

%title= h yield(:title)

But how to set this header, but if it does not exist, set the default value?

+5
source share
1 answer

Use the method content_for?as described in the Rails API

content_for?(:title) ? yield(:title) : "default title"
+8
source

All Articles