Skip to content

Instantly share code, notes, and snippets.

@adrianpike
Created October 27, 2011 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adrianpike/1320999 to your computer and use it in GitHub Desktop.
Save adrianpike/1320999 to your computer and use it in GitHub Desktop.
Page title helper for I18n with to_s for :show!
def page_title()
object_name = controller_name.singularize
if controller.instance_variables.include?(('@' + object_name).to_sym)
locals = {
object_name.to_sym => controller.instance_variable_get('@' + object_name).to_s
}
else
locals = {}
end
I18n.t([controller_name, action_name].join('.'), locals)
end
### meanwhile, in en.yml
en:
foos:
index: "showing foos"
show: "check out this awesome %{foo}"
edit: "editing %{foo}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment