title: Ordering Rails Array of Json's by the key "updated_at" 's value
body: <p>I am trying to order an array of jsons by a value.</p>
  
  <p>I cannot just query the database with <code>.order('created_at DESC')</code> because my array is filled with information from 2 different tables.</p>
  
  <p>Here is the code that I  have so far:</p>
  
  <pre><code>@user_items = UserItem.where(user_id: @friends.to_a).order('created_at DESC')
  @user_pics = Pic.where(user_id: @friends.to_a).order('created_at DESC')
  @all_things = @user_pics + @user_items
  @all_things.sort_by{"updated_at"}
  </code></pre>
  
  <p>This does not error but when I run the code the first things in the list are always all the pictures followed by all the items. So, it seems the list line of code is doing nothing.</p>
  
  <p>Here is a sample of what <code>user_pics[0]</code> looks like:</p>
  
  <p><code>{"id"=&gt;15, "user_id"=&gt;2, "name"=&gt;"New titles", "creator"=&gt;nil, "size"=&gt;nil, "created_at"=&gt;Sun, 14 Feb 2016 02:41:12 UTC +00:00, "updated_at"=&gt;Sun, 14 Feb 2016 02:41:12 UTC +00:00 ...}</code></p>
  
  <p>EDIT 1</p>
  
  <p>Sadly, the suggested answer does not seem to be working. Below are a few different outputs. Firstly, a pic that was updated Feb 14, then items that were updated Feb 24 and Feb 13 respectively. It seems the array is still ordered with all pictures first then all items.</p>
  
  <blockquote>
    <blockquote>
      <p>@all_things.sort_by { |a| a[:updated_at] } [0]
      => {"id"=>15, "user_id"=>2, "name"=>"New titles", "creator"=>nil, "size"=>nil, "mark_count"=>nil, "created_at"=>Sun, 14 Feb 2016 02:41:12 UTC +00:00, "updated_at"=>Sun, 14 Feb 2016 02:41:12 UTC +00:00 ... }</p>
      
      <p>@all_things.sort_by { |a| a[:updated_at] } [4]
      => {"id"=>846, "item_id"=>669, "user_id"=>2, "created_at"=>Wed, 24 Feb 2016 16:43:54 UTC +00:00, "updated_at"=>Wed, 24 Feb 2016 16:43:54 UTC +00:00, ...}</p>
      
      <p>@all_things.sort_by { |a| a[:updated_at] } [50]
      => {"id"=>797, "item_id"=>623, "user_id"=>2, "created_at"=>Sat, 13 Feb 2016 03:58:29 UTC +00:00, "updated_at"=>Sat, 13 Feb 2016 03:58:29 UTC +00:00, ...}</p>
    </blockquote>
  </blockquote>