Easy titles in Rails
application_helper.rb
def site_title; "Acme Widgets Corp"; end
def t(str); textilize_without_paragraph(@title = str); end
def title; @title.blank? ? site_title : "#{@title} - #{site_title}"; end
some_action.html.erb
<h1><%= t "Omnivorous Widgets" %></h1>
application.html.erb
<title><%= title %></title>
Oh, the protestations
I can hear it now, “But… but… it’s all hard-coded!”
Yes. Yes, it is. But it’s three lines, easy to remember, easy to change, distinctly non-clever, and very, very DRY.