-
-
Save amiel/1321006 to your computer and use it in GitHub Desktop.
Page title helper for I18n with to_s for :show!
This file contains hidden or 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, 'title'].join('.'), locals) | |
end | |
### meanwhile, in en.yml | |
en: | |
foos: | |
index: | |
title: "showing foos" | |
show: | |
title: "check out this awesome %{foo}" | |
edit: | |
title: "editing %{foo}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Translate with all the controller instance variables
def tv(key, opts)
locals_hash = controller.instance_variables.collect{|var|
unless var.to_s.match(/^@/) then
[var.to_s.match(/^@(._)/)[1].to_sym, controller.instance_variable_get(var).to_s] rescue nil
end
}.compact
end