You’re not receiving notifications from this thread.
Order by score using Pagy pagination?
Hi everyone. I am currently trying to order some ActiveRecord records by score. In my controller i have:
def index @pagy, @drivers = pagy( Driver.select( 'drivers.*', '(drivers.no_races + drivers.no_poles + drivers.no_podiums + drivers.no_wins) AS score' ).reorder('drivers.score DESC'), page: params[:page], items: 16 ) end
I am using Pagy for the pagination. As the code shows, I do a query to select all drivers and then add together 3 columns in the table as 'score'. I then want to order by score going from high to low and show 16 records per page.
When the page loads it seems to order by driver id. I can't see anywhere else that i have an order by, but i did add reorder to override anything else.
Anyway for whatever reason i'm stuck with the wrong ordering. Any direction is appreciated :-)
Mockup - http://29qg.hatchboxapp.com/drivers
do you have some
I've just checked and i don't have
default scope anywhere
@joshBrody - just check
default scope is only going to be in the model or the controller i guess?