我有一個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