balanv
balanv

Reputation: 10898

Cannot access translate value in Class files (Rails)

I am using locale file to save the English text, and I am using these text in controller by calling it like t(:user_created_message).

But when I moved my logic to a class file under /lib/classes/users/user.rb and tried to access the translate, it shows error like undefined method t for Users::User

How should I load the translate variable when calling from custom classes?

Upvotes: 1

Views: 146

Answers (1)

Luís Ramalho
Luís Ramalho

Reputation: 10218

I18n.t :user_created_message

Please read the documentation here, the method you're using only works inside the views.

Upvotes: 2

Related Questions