Ruby on Rails - ordering in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
Example:
We can order ActiveRecord query results by using .order:
- If not specified, ordering will be performed in ascending order.
- We can specify it by doing:
- .order also accepts a string.
We could also do:
- As the string is raw SQL, we can also specify a table and not only an attribute. Ensure that we want to order users according to their role name.
- We can do this:
The order scope can also accept an Arel node: