很難說出這一個,但基本上我有一個遊戲集合。我讓他們輸出到一張桌子,我想要一個'評級'的列 - 這是您的個人評分,因此它將是互動的。只適用於第一個版本的動態表格(Rails)
我找不出合適的方法來做到這一點,所以我去了HTML/CSS - 我用了一個'表單',以便以後可以將它提交給數據庫。所有這些都是我自己的創可貼,請告訴我是否有更簡單的方法。
我現在的問題是我按下的任何評級按鈕,只在第一排工作。我嘗試使用ERB來製作表格(想知道這是否有一些魔法變化),並且將for_each
的'索引'附加到字段中,但沒有骰子。事實上,這樣做使得頂級域只能提交一次而不再提交。
表生成
<table class="table">
<thead>
<tr>
<th class="text-center">#</th>
<th>Game Icon</th>
<th>Game</th>
<th>Playtime</th>
<th>Rating</th>
<th class="text-right">Cost</th>
<th class="text-right">Actions</th>
</tr>
</thead>
<tbody>
<% gamesList.each_slice(3) do |games| %>
<% games.each_with_index do |game, index| %>
<tr>
<td class="text-center"><%= index %></td>
<td><%= game['name'] %></td>
<td>
<% if game['img_icon_url'].blank? %>
<%= image_tag 'http://www.readyicons.com/IconSets/Sky_Light_(Basic)/32x32-no.png' %>
<% else %>
<%= image_tag "http://media.steampowered.com/steamcommunity/public/images/apps/#{game['appid']}/#{game['img_icon_url']}.jpg" %>
<% end %>
</td>
<td><%= game['playtime_forever'] %></td>
<td>
<div class="stars">
<form action="">
<input class="star star-5" id="star-5" type="radio" name="star<%=index%>"/>
<label class="star star-5" for="star-5"></label>
<input class="star star-4" id="star-4" type="radio" name="star"/>
<label class="star star-4" for="star-4"></label>
<input class="star star-3" id="star-3" type="radio" name="star"/>
<label class="star star-3" for="star-3"></label>
<input class="star star-2" id="star-2" type="radio" name="star"/>
<label class="star star-2" for="star-2"></label>
<input class="star star-1" id="star-1" type="radio" name="star"/>
<label class="star star-1" for="star-1"></label>
</form>
</div>
</td>
<td class="text-right">$19.99(Static-TBD)</td>
<td>Stuff</td>
</td>
</tr>
</tr>
<% end %>
<% end %>
</tbody>
</table>
我歡迎任何輸入,即使它完全改變了我是如何做的。 (我不知道Rails是否有'小提琴',所以我無法效仿這個。)
(PS我會在不同的控制器上大量使用收視率 - 如果有寶石或更好的Rails Way 「對於這一點,我絕對是所有的耳朵。)
感謝您的代碼片段。我會觀看railscast以更好地理解它 - 我嘗試了您的卡,但它提供了一個空白下拉列表。當我檢查它時,我確實看到了'。 – DNorthrup
剛剛編輯,我以前的代碼以前使用表單博客,我只是編輯使用簡單的select_tag,如果你以後使用形式博客form.select標記,那麼這將工作<%= form.select:index,[1,2,3, 4,5],include_blank:false%> – widjajayd