I have this query:
@cars = Car.paginate(page: params[:page], per_page: 5).order(created_at: :desc).group_by { |r| r.created_at.to_date }
and in
You can do something like this in your controller:
@car_paginator = Car.paginate(page: params[:page], per_page: 5).order(created_at: :desc)
@cars = @car_paginator.group_by { |r| r.created_at.to_date }
Then change the line with the pagination in your view:
= will_paginate @car_paginator
The problem is: When you use the paginate
method the results is not a normal array or database relation but an object that has some extra information like @size
. If you run group_by
on that you remove that extra attributes and return a plain hash.