119 Labs LLC

Ideas on Technology

Page Title Helper in Rails 3

I was looking to DRY up my page titles but was having some trouble with Rails 3 view contexts. Here’s what I finally ended on:   Just place this method in your application_helper.rb. This automatically looks for an entry in your translation store based on the path of the view template which you call the helper from. So if you you have a template under user_sessions/new.html.erb like this:   And an entry in en.yml like this:   It will automatically generate an H1 containing your translated text.