如何在视图中列出yml
中的元素并循环遍历它们以访问其属性? 我目前的代码只能获取列表中的最后一项。我想在视图中循环遍历项目列表并显示它们的title
和description
元素。
例如:
yml:
en:
hello: "Hello world"
front_page:
index:
description_section:
title: "MyTitle"
items:
item:
title: "first item"
description: "a random description"
item:
title: "second item"
description: "another item description"
视图:
<%= t('front_page.index.description_section.items')do |item| %>
<%= item.title %>
<%= item.description %>
<%end %>
结果:
{:item=>{:title=>"second item", :description=>"another item description"}}
期望结果:
first item
a random description
second item
another item description
.each
以使其正确循环。 - DogEatDog