Reputation: 9184
How can I set the page title in some views and use a default title if it's not set?
I use HAML. What is right way of doing it?
Now I do like:
- content_for :title, "Title for specific page"
and in layout:
%title= h yield(:title)
But how to set this title, but if it doesn't exist, set some default value?
Upvotes: 5
Views: 2155
Reputation: 5034
Use the content_for?
method as described in the Rails API
content_for?(:title) ? yield(:title) : "default title"
Upvotes: 8