【发布时间】:2015-04-22 17:44:42
【问题描述】:
如何在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
【问题讨论】: