0
我想为我的表创建可排序的列,这些列根据散列制表数据。通过以下http://railscasts.com/episodes/228-sortable-table-columns?view=asciicast。据我所知,订单方法只会工作整理一个模型。整理这些表格的列的最佳方法是什么?我提到了29个类似的表格。我的代码如下: -基于散列和键阵列的可排序表列
admins_controller.rb
class AdminsController < ApplicationController
array =[]
User.each do |user|
company_name = Company.find(user.company_id).name
array.push(company_name)
end
company = array.inject(Hash.new(0)) { |h, e| h[e] += 1 ; h }
end
的上述查询上述研究是这样的: -
array = [["3M", 4], ["A.P. Møller-Mærsk Group", 10], ["ABB", 14], ["Abbott Laboratories", 12]]
的看法: -
管理员.html.erb
<table class="table">
<tr>
<th><%= link_to "Company", remote: true, :sort => "hash" %></th>
<th><%= link_to "Value", remote: true, :sort => "key" %></th>
<th><%= link_to "Percentage", remote: true, :sort => "Percentage" %></th>
</tr>
<% if @mentors.try(:any?) %>
<% @mentors.each do |key, value| %>
<tr>
<td><%= key %></td>
<td><%= value %> </td>
<td><%= ((value.to_f/@total_co.to_f).to_f * 100).round(2)%> </td>
</tr>
<% end %>
<% else %>
<td> nil </td>
<td> nil </td>
<td> nil </td>
<% end %>
</table>