using translation in the link_to in ROR
-
03-10-2019 - |
Question
HI ,
In ROR , i m having a line like
<%= link_to("NAME (#{@name})", user_path(@user, :in => :s)) %>
i want to change the string NAME to t(:str_name) ..
how to change it . when i change it , i am getting errors..
Solution
Put your translation in corresponding .yml files in /config/locales For example in /config/locales/en.yml
en:
link_text:
name: "Name (%{:name})"
Then from your views:
<%= link_to(t('link_text.name', :name => @name), user_path(@user, :in => :s)) %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow