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

蓝咒 提交于 2019-12-10 00:51:31

问题


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.




回答3:


Thanks Skydan but extend would work only for modules. I made it work by adding include ActionView::Helpers::TranslationHelper to my controller.



来源:https://stackoverflow.com/questions/21878676/undefined-method-t-for-adminfaqscontrollerclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!