我有一个Rails 3.2视图,正在创建一个列表。如果costestimate.costcat.position
等于1(列表中只有一个),我想保存一个变量用于列表的其余部分。导轨 - 保持一个变量,当你通过。每个
<% @costproject.costestimates.each do |costestimate| %>
<% if costestimate.costcat.position = 1 %>
<% $constructioncost = costestimate.amount %>
<% end %>
<% if costestimate.costcat.typical != nil %>
<% costtypical = costestimate.costcat.typical * $constructioncost %>
<% end %>
<td><%= costtypical %></td>
<td><%= costestimate.notes %></td>
但是,在每个周期后,$ constructioncost变为零。我认为$会使它成为一个全局变量。
移动它的外循环的工作 - 感谢 – Reddirt