Rails 3.2群计与Kaminari

时间:2014-01-19 08:40:28

标签: ruby-on-rails activerecord kaminari

我试图在我的表格中显示最受欢迎的标记词,按展示次数排序。然后通过记录添加kaminari到paginate。

在我的控制器中我试过了:

@tag_answers = Tag.group(:content).page(params[:page]).order("count_all DESC").count

在我看来:

<table>
  <thead>
     <th>Tag</th>
     <th>Count</th>
  </thead>
  <tbody>
    <% @tag_answers.each do |tag_content, tag_count| %>
      <tr>
         <td> <%= tag_content %> </td>
         <td> <%= tag_count %> </td>
      </tr>
    <% end %>
  </tbody>
</table>
<%= paginate @tag_answers %>

但是我收到以下错误

undefined method `current_page' for #<ActiveSupport::OrderedHash:0x000001031b8678>

1 个答案:

答案 0 :(得分:1)

尝试

@tag_answers = Tag.group(:content).select('content, COUNT(*) as count').order("count DESC").page(params[:page])