Skip to content

Instantly share code, notes, and snippets.

@rzzo
Last active February 1, 2024 08:34
Show Gist options
  • Save rzzo/234dc962421c8742950b40be78a318a5 to your computer and use it in GitHub Desktop.
Save rzzo/234dc962421c8742950b40be78a318a5 to your computer and use it in GitHub Desktop.
Simple to set a page title dynamically Ruby on Rails. Set page title with ternary operator
<!-- Set page title with ternary operator -->
<!-- application layout -->
<title><%= content_for?(:page_title) ? yield(:page_title) : default_page_title %></title>
<!-- view -->
<% set_page_title(@page_title) %>
<!-- application helper -->
def set_page_title(title)
content_for :page_title, title
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment