ruby-on-rails-3internationalizationtranslationrails-i18nruby-1.9.3

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


I am using i18n in rails 3.0.3 and user have functionality to edit text. If user save text then it comes from database instead of en.yml file. I have override t helper like below:

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

and then

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

I am calling this method from view:

<h1 <%= c_t '.title' %></h1>

It was working fine in rails 2.3 but after upgrading rails to 3.0.3 I am getting error **undefined method `template' for Class


Solution

  • use this helper method in rails 3

     view_context.instance_variable_get(:@_virtual_path)