19

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?

Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133

3 Answers3

56

Use I18n.t instead of just t.

Andrea Salicetti
  • 2,423
  • 24
  • 37
  • I was getting the same error when using in custom library file. This solves the problem. Thanx! – Hardik Apr 25 '14 at 06:28
  • 2
    If you feel verbose to call `I18n.t` every time, you can add this line to your `ApplicationController`: `delegate :t, to: I18n` – Aetherus Aug 24 '17 at 08:22
  • 1
    Hey but with `I18n.t` or `delegate :t, to: I18n` you cannot make use of lazy_lookout you have to name the whole thing. `t('.home.index.logged_in')` intead of `t(.logged_in)` – Daniel Sibaja Feb 01 '19 at 21:18
4

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

Skydan
  • 1,196
  • 1
  • 12
  • 24
0

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

Vitalii Prodan
  • 175
  • 2
  • 12