skanev/evans — pull request #113 by mitio (2013-12-15 13:19:58+00:00)
Title: Fix users sorting and pagination

С промените по team page сме счупили още нещо на сайта – подредбата на потребителите, както и броят потребители на страница.

Ето защо се чупи и какво решение предлагам аз (из 795c0bc):

First, it turns out that defining User.page does not work well with
scopes, meaning that User.page is totally ignored and not called when
after a scope, like this: User.students.page(...). This is breaking our
ordering as well as our custom per_page parameter. This seems to be
caused by the name of the method "page" being defined in the relation
probably by will_paginate and thus the AR relation does not delegate
back to User.page. I see two possible ways to fix this:

1. Redefine ActiveRelation#page method with our version as well as keep
User.page.
2. Just use a different name for User.page (I came up with User.at_page)
so that AR will not have this method defined and will delegate back
to our User model.

I chose the second way to solve this issue.

Second, I think it's a good idea to have separate sorting and pagination
concerns since the old User.page method did not indicate in any way that
it also performs sorting under the hood.