1
我在.erb文件中的函數,並在它,我有以下幾點:如何更改順序的兩個項目中。每次在紅寶石
<%select id ="dropdown">
<option disabled selected value="select"> - select - </option>
<% @variable.each do |x| %>
<%= "<option value='#{x['code']}'>#{x['description']} </option>".html_safe %>
<% end %>
<%/select>
但是我需要有兩個項目(TUA和CRL)顯示在頂部,其餘部分以字母順序顯示(當前是),因此它應該是。
<%select id ="dropdown">
<option disabled selected value="select"> - select - </option>
<% @variable.each do |x| %>
<% next if x['code'] == 'TUA' or x['code'] == 'CRL' %>
<%= "<option value='#{x['code']}'>#{x['description']} </option>".html_safe %>
<% end %>
<%/select>
我該怎麼做?我對它進行了硬編碼,我不想那樣。
@variable在控制器中定義,它是一個Web服務返回調用。 – Remon87
@Remon87做了上述工作? – gwalshington
不幸的是它沒有工作。此外,我需要在erb文件中修復,而不是在控制器中。我仍然試圖弄清楚。 – Remon87