Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails set page title in view

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?

like image 209
brabertaser19 Avatar asked Mar 22 '13 14:03

brabertaser19


1 Answers

Use the content_for? method as described in the Rails API

content_for?(:title) ? yield(:title) : "default title"
like image 122
Simon Woker Avatar answered Sep 26 '22 04:09

Simon Woker