<style>
  #users {width:600px;text-align: center}
  #users thead {line-height:25px; background-color:#1c1b1b; height:25px; color:#d6edff; font-weight:bold;}
  #users tbody {line-height:25px; padding-top:3px; font-weight:bold; }
  #users .index {color:#d6edff}
  #users .me {color:deepskyblue}
  #users .name a {color:#FFE793}
  #users .credits {color:#FF6468}
  #users .ratio {color:#58DB3E; text-align:right}
  #users .win {color:red; text-align:right}
  #users .lost {color:blue; text-align:right}
  #users .show a {color:#DFC84B}
</style>

<table id="users">
  <thead>
    <tr>
      <th>名次</th>
      <th>决斗者</th>
      <th>积分</th>
      <th>胜率</th>
      <th>胜</th>
      <th>负</th>
      <th>得分纪录</th>
    </tr>
  </thead>
  <tbody>
    <% top_users = User.order(:credits).reverse_order.limit(10) %>
    <% if logged? && !top_users.include?(@current_user) %>
      <% top_users << @current_user %>
      <% my_index = User.where("credits>=?", @current_user.credits).count %>
    <% end %>
    <% top_users.each_with_index do |user, index| %>
      <tr>
        <% if user == @current_user %>
          <td class="index me"><%= my_index %></td>
        <% else %>
          <td class="index"><%= index.next %></td>
        <% end %>
        <td class="name"><%= link_to user.name, user %></td>
        <td class="credits"><%= user.credits %></td>
        <% win = user.wins.count %>
        <% all = user.duels.count %>
        <td class="ratio"><%= all.zero? ? 0 : 100 * win / all %>%</td>
        <td class="win"><%= win %></td>
        <td class="lost"><%= all - win %></td>
        <td class="show"><%= link_to '详情', user %></td>
      </tr>
    <% end %>
  </tbody> 
</table>