0

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.

1

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.