I'm using Kaminari to paginate many schools objects but I have to order them by ratings, but something went wrong : the pagination is ok but the gem order by rating for each page of the pagination, and not for all schools present in all page, for example :
page 1 -> school 1 - rate 20, school 2 - rate 10, school 3 - rate 0
page 2 -> school 4 - rate 12, school 5 - rate 6, school 7 - rate 0
page 3 -> ...
and I want :
page 1 -> school 1 - rate 200, school 2 - rate 120, school 3 - rate 100
page 2 -> school 4 - rate 90, school 5 - rate 90, school 6 - rate 85
...
here is my code :
def index
@schools = School.where(:subscription.exists => false).page(params[:page]).per(50)
@schoolss = @schools.sort_by(&:ratings_count).reverse
end
and the view
<tbody>
<% @sch.each do |school| %>
<tr>
<th> <%= link_to school.title, school.path_school_profile %> </th>
<th> <%= school.city %> </th>
<th> <%= school.ratings.count %> avis | <%= school.avg_ratings_score_round %>/5 </th>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @schools %>
<%= page_entries_info @schools %>
Does someone could help me ?
you sorted @schools to new variable(@schoolss), why not use it??
change your index controller to this
def index
@schools = School.where(:subscription.exists => false).order_by(:ratings_count => 'desc').page(params[:page]).per(50)
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.