-->

undefined method `t' for Admin::FaqsController

2019-04-18 13:38发布

问题:

in my project i have controller in namespace admin and I'm using breadcrumbs_on_rails to build breadcrums. My controller looks like: module Admin

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

i can use t method in new, edit and other controller action but when this 't' is not in the controller action i have the follwoing error:

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

Any ideas?

回答1:

Use I18n.t instead of just t.



回答2:

I can suggest to extend your class with extend ActionView::Helpers::TranslationHelper It will allow you to use #t and #l helpers.