template.path_without_format_and_extension 不适用于 rails 3.0.3。获取未定义的方法模板

template.path_without_format_and_extension Not working in rails 3.0.3. Getting undefined method template

我在 rails 3.0.3 中使用 i18n,用户可以编辑文本。如果用户保存文本,那么它来自数据库而不是 en.yml 文件。我有 override 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 后出现错误 ** Class

的未定义方法“模板”

在 rails 中使用此辅助方法 3

 view_context.instance_variable_get(:@_virtual_path)