How to use the HAML t() helper in RoR

2019-08-13 15:40发布

问题:

I'm developing an application with Rails 4 and I want to use the helper t() with HAML, but I can not

Example usage:

=model_name = @article.class.model_name.human
%h1 Create  t(:model_name)

My first line shows me the correct article, but when I use t() it shows me t(:model_name). Thanks.

回答1:

hope in translational file you have en.yml

en:
  article: MyArticle

Then

%h2= t 'article'

if you want dynamically ``

%h2= t '#{model_name}'