我在rails 3.0.3中使用i18n,用户可以编辑文本。如果用户保存文本,则它来自数据库而不是en.yml文件。我有覆盖t帮助器,如下所示:
def c_t(key, options = {})
c_key = (scope_key_by_partial_custom(key)).gsub(".","_")
if $LAYOUT_CONTENTS[c_key].present?
$LAYOUT_CONTENTS[c_key]
else
t(key,options)
end
end
然后
def scope_key_by_partial_custom(key)
if key.to_s.first == "."
template.path_without_format_and_extension.gsub(%r{/_?}, ".") + key.to_s
else
key
end
end
我从视图中调用此方法:
<h1 <%= c_t '.title' %></h1>
它在rails 2.3中运行良好但是在将rails升级到3.0.3之后我收到了错误 **类
的未定义方法`模板'答案 0 :(得分:1)
在rails 3中使用这个辅助方法
view_context.instance_variable_get(:@_virtual_path)