Skip to content

Instantly share code, notes, and snippets.

@jnx
Forked from rzzo/dynamic_title_rails.html.erb
Created February 1, 2024 08:34
Show Gist options
  • Save jnx/d57d609a3090d30fca9216ad656399f5 to your computer and use it in GitHub Desktop.
Save jnx/d57d609a3090d30fca9216ad656399f5 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