Ildar
Ildar

Reputation: 343

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"]

Upvotes: 1

Views: 1003

Answers (1)

MattMcKnight
MattMcKnight

Reputation: 8290

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.

Upvotes: 1

Related Questions