title: How to get only last records grouped by some value in Rails
body: <p>I have model Message (id, text, sender_id, recipient_id, created_at).
  I need to get only last records in scope of each recipient_id. It's like in most messangers page with all conversations.</p>
  
  <p>For example, I have this (recipient is current_user):</p>
  
  <pre><code>id, sender_id, created_at
  1, 1, 10.04.15
  2, 1, 11.04.15
  3, 2, 12.04.15
  4, 3, 13.04.15
  5, 2, 14.04.15
  </code></pre>
  
  <p>With query I need to get only values with ids 2, 4, 5, grouped by :</p>
  
  <pre><code>id, sender_id, created_at
  2, 1, 11.04.15
  4, 3, 13.04.15
  5, 2, 14.04.15
  </code></pre>
  
  <p>With this select we have all the records, grouped by user:</p>
  
  <pre><code>Message.order(created_at: :desc).group_by(:sender_id)    
  </code></pre>