Admin :: FaqsController的未定义方法`t’:Class

在我的项目中,我在命名空间管理员中有控制器,我正在使用breadcrumbs_on_rails来构建breadcrums。 我的控制器看起来像:模块管理员

class FaqsController < Admin::ApplicationController include FaqsHelper load_and_authorize_resource add_breadcrumb t('faqs.faqs_list') , :faqs_path #this line makes the problem def index @faqs = @faqs add_breadcrumb t('faqs.faqs_list') end def new add_breadcrumb t('faqs.new') end #other code ommitted end end 

我可以在新的,编辑和其他控制器动作中使用t方法但是当这个’t’不在控制器动作中时,我有以下错误:

 undefined method `t' for Admin::FaqsController:Class 

有任何想法吗?

使用I18n.t而不是t

我可以建议用extend ActionView::Helpers::TranslationHelper来扩展你的类。它允许你使用#t#l helpers。