Created
October 27, 2011 21:56
-
-
Save adrianpike/1320999 to your computer and use it in GitHub Desktop.
Page title helper for I18n with to_s for :show!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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