我有下表,其中顯示了匹配結果以及該匹配的登錄用戶選擇。當數據庫中沒有相關記錄時,我想在selection.winner和selection.value列中顯示文本值,但我不確定如何執行此操作。我的代碼如下:如果數據庫中存在空值,則顯示字符串
<% Fixture.where(:weekno => @gameweek.number).each do |fixture| %>
<tr>
<td width="10"><%= fixture.date.strftime("%d/%m/%Y")%></td>
<td width="10"><%= fixture.date.strftime("%H:%M") %></td>
<td width="80"><%= fixture.home_team %></td>
<td width="10">Vs.</td>
<td width="80"><%= fixture.away_team %></td>
<td width="10"><%= fixture.result %></td>
<% Selection.where(:userid => current_user.id, :fixtureno => fixture.id).each do |selection| %>
<td width="10"><%= selection.winner %></td>
<td width="10"><%= selection.value %></td>
<% end %>
</tr>
<% end %>
嘿沙德韋爾非常感謝您的幫助這解決了我的問題:)我打算要每名用戶遊戲週期只有1個選擇,以便這不應該是一個問題,但感謝的頭up :-) – 2011-12-21 13:45:46