[2342] Prevent DB access during rake tasks

Fixes #2342 by lazy-loading the sort order, which depends on DB access. Since when using Heroku the asset precompile task doesn't have access to the DB, this was an issue for many users.

Note that prior to Rails 4 the DB was needed just to load the app, so this change wasn't necessary until now.