使用循环将 locales yml 文件中的数组输出到 erb?
output an array from locales yml file to erb using a loop?
我是 ruby 的新手。我有一个来自 config\locales\en.yml
的数组
sample_array:
- list1
- list2
- list3
- list4
我正在尝试使用 do 循环
将其输出到 erb
<% sample_array.each do |list| %>
<p><%= list %></p>
<% end %>
我的预期结果:
list1
list2
list3
list4
相反,我收到一条错误消息 未定义的局部变量或方法
使用 I18n.t('key')
或 t('key')
检索语言环境文件中的值。尝试
<% t('sample_array').each do |item| %>
<p><%= item %></p>
<% end %>
我是 ruby 的新手。我有一个来自 config\locales\en.yml
的数组sample_array:
- list1
- list2
- list3
- list4
我正在尝试使用 do 循环
将其输出到 erb<% sample_array.each do |list| %>
<p><%= list %></p>
<% end %>
我的预期结果:
list1
list2
list3
list4
相反,我收到一条错误消息 未定义的局部变量或方法
使用 I18n.t('key')
或 t('key')
检索语言环境文件中的值。尝试
<% t('sample_array').each do |item| %>
<p><%= item %></p>
<% end %>