我目前正在爲軌道上的紅寶石戰艦遊戲做板。 我被困在如何更改表格單元格的顏色(取決於數組中的哪些值@actions是內部的。我嘗試使用case語句,並且if'statement在html.erb中,但我無法找到正確的語法而我想知道另一件事:我應該爲此做一個輔助方法和在HTML中使用它,而不是在那裏編碼根據使用erb的單元格值設置表單元格的不同顏色 - 在軌道上使用紅寶石
這裏是控制器:
class BoardsController < ApplicationController
def new
@actions = ['none', 'hit', 'miss', 'ship', 'special']
@grid = []
for row in 0..9
@grid.push([])
for column in 0..9
@grid[row].push({
'action' => @actions.sample
})
end
end
end
end
這裏是視圖:
<table class="table table-striped table-bordered">
<% for row in 0..9 %>
<tr>
<% for column in 0..9 %>
<td>
<%= @grid[row][column]['action'] %>
</td>
<% end %>
</tr>
<% end %>
</table>
請編輯您的問題的帖子相關的代碼(即視圖和控制器)。 – Gerry
歡迎來到這裏:)你需要在這裏發佈你的當前代碼。不是全部,只是關鍵部分。另外,快速拼寫檢查不會受到傷害。 –
海事組織它可能是最簡單的分配相關單元類,並使用JavaScript來做樣式。 – engineerDave