我有一个非常简单的ERB文件,它循环遍历数据库,并为特定用户特定的Bootstrap格式化数据。一切看起来都很棒,但最后在所有div之后,它包含的输出看起来就像你使用控制台过滤具有相同user_id的项目一样。
我觉得我只是错过了一些简单的东西,但我找不到它。此外,如果我销毁给定用户的所有交易,则else语句会正确输出。
文件
<% if @user.deals.any? %>
<%= @deals.each do |deal| %>
<div class="row">
<div class="col col-xs-12">
<%= deal.headline %>
</div>
</div>
<div class="row">
<div class="col col-xs-3">
<%= deal.client %>
</div>
<% if deal.matter? %>
<div class="col-xs-3">
<%= deal.matter %>
</div>
<% end %>
<% if deal.summary? %>
<div class="col-xs-6">
<%= deal.summary %>
</div>
<% end %>
</div>
<% end %>
<% else %>
<div class="row">
<div class="col col-xs-12">
<h4>Add your first deal to see a list here!</h4>
</div>
</div>
<% end %>
数据行后的附加输出
[#<Deal id: 18, client: "Headline and client only", matter: "", summary: "", user_id: 2, created_at: "2017-02-08 15:09:28", updated_at: "2017-02-08 15:09:28", headline: "Healine and client only">, #<Deal id: 17, client: "First client", matter: "First matter", summary: "First summary", user_id: 2, created_at: "2017-02-08 15:07:45", updated_at: "2017-02-08 15:07:45", headline: "First headline">]
答案 0 :(得分:1)
相反
<%= @deals.each do |deal| %>
使用
<% @deals.each do |deal| %>
注意 = 消失了
有关详细信息,请参阅What is the difference between <%, <%=, <%# and -%> in ERB in Rails?; - )