【发布时间】:2015-12-22 14:47:25
【问题描述】:
控制器:
def show
@recipe = Recipe.find(params[:id])
@ingredients = @recipe.ingredients
@steps = @recipe.steps
end
模板:
<%= @steps.each do |step| %>
<li>
<%= step.sequence %>
<%= step.description %>
</li>
<% end %>
传递给我的模板的对象数组正在被迭代,然后在最后显示实际的字段数组(在图片中的第 5 步下方)。我想显示每个对象的属性,而不是实际的对象列表。
我做错了什么?
【问题讨论】:
-
你想不清楚但
<%= @steps.to_sentence %>或<%=@steps%>this会显示数组 -
将
<%= @steps.each更改为<% @steps.each。使用%=会以文本形式呈现给页面,这不是您想要的。
标签: ruby-on-rails ruby templates erb