I have a model called Products and in that model I have a column called "Size". How can I order sort my products by their size? (Something like 9, 9.5, 10, 10.5, 11).
Thanks.
I have a model called Products and in that model I have a column called "Size". How can I order sort my products by their size? (Something like 9, 9.5, 10, 10.5, 11).
Thanks.
If you have to have the field as a string, you can do
Product.all.sort_by{|p| p.size.to_f}
However, if you can change the field from a string to a float you can do the more efficient..
Product.order(:size)