John
John

Reputation: 6612

Order on integer value

I have an integer column "level". I want to order on level by doing this in the controller:

@leagues = League.all.order('level')

This results in 1, 10, 2, 3 as results, where I would expect 1, 2, 3, 10 as results. How can I solve this?

Upvotes: 0

Views: 1734

Answers (2)

Marcelo Júnior
Marcelo Júnior

Reputation: 445

Try only League.order('level')

Upvotes: 1

Anthony Alberto
Anthony Alberto

Reputation: 10395

Sounds like you created the column as a string in the DB ... if it was a int, you'd get 1, 2, 3, 10 ... at least with MySQL!

Upvotes: 1

Related Questions