Answer the question
In order to leave comments, you need to log in
How can I sort numbers in string types in Ruby on Rails (MySQL database)?
There is a table. And there is a string type field, for example, house_number.
This field usually stores numbers.
And I want to sort this field so that the numbers go in order ( .order(:house_number) ).
But this does not happen, because the field is of string type.
Are there solutions to this problem?
Answer the question
In order to leave comments, you need to log in
For example, Model.all.sort_by { |instance|| instance.house_number.to_i }
didn't really check, no rails at hand
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question