Question

I am trying to display in my a table with most popular tag words, ordered by the count of impression. Then add kaminari to paginate through the records.

in my controller I tried:

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

and in my view:

<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 %>

but i am getting the following error

undefined method `current_page' for #<ActiveSupport::OrderedHash:0x000001031b8678>
Was it helpful?

Solution

Try

@tag_answers = Tag.group(:content).select('content, COUNT(*) as count').order("count DESC").page(params[:page])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top