很难说出这一个,但基本上我有一个游戏集合。我让他们输出到一张桌子,我想要一个'评级'的列 - 这是您的个人评分,因此它将是互动的。只适用于第一个版本的动态表格(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