Rails: query doesn't order with special characters
I want to query elements with order by name.
If 开发者_如何学编程I simply write Element.all.order('name') then I receive: aaa bbb _ccc ddd
But I want: _ccc aaa bbb ddd
I want this because I think adding "_,-,=" is the simplest way to make visual order on the page.
Is it possible to achieve this in query? Or should I just use ruby 'sort' method?
Thank you!
In console I can do this: ['aaa', 'bbb', '_ccc'].sort => ["_ccc", "aaa", "bbb"]
The difference is that order on the Element.all.order() is generating SQL Order By, while ruby sort is a different algorithm, and can be customized in your model code. Modifying how your database sorts is going to be specific to that database, and may be a configuration option related to your character set.
精彩评论