Rails: Sort nils to the end of a scope?
问题 So, I have the following scope in my Photo model: scope :best, order(:average_rating.desc) The only problem is, the ratings were added to the model after the fact, so the production app has a lot of records where average_rating is nil. When I call this scope it returns all the nils first -- in fact it should be the opposite, nils should be last ( they are photos which have not yet been rated ). How can I sort nils to the end of this scope? 回答1: I'm a bit late to the game but this just came up