Skip to Content

Rails - Ordering active record

Posted on

Simple order

We use order to sort records in some ways. For example: Post.order created_at: :desc


If you want to override previously set order (even through default_scope), use reorder() instead.

User.order(id: :asc).reorder(name: :desc)

will ignore ordering by id completely

Ordering on associations

  • Using includes

  • Using merge

   current_user.conversations.joins(:message).merge(Message.order created_at:
comments powered by Disqus