title: Accessing values in array of hashes where the values are arrays of hashes
body: <p>I'm in an array &amp; hash rabbit hole, please excuse verbose question.</p>
  
  <p>I'm trying to display values in a view. I created my hash by combining hashes together and grouping them by a value, so my data looks like this:</p>
  
  <pre><code>[
    {"447478xxxxxx"=&gt;[
                       {:cbrs=&gt;[
                                 {"telephone_number"=&gt;"447478xxxxxx", "type"=&gt;"cbr"}
                               ]
                       }, 
                       {:pupil_calls=&gt;"0"}, 
                       {:returned_calls=&gt;"0"}
                      ]
    }, 
    {"447440xxxxxx"=&gt;[
                      {:cbrs=&gt;[
                                {"telephone_number"=&gt;"447440xxxxxx", "type"=&gt;"cbr"}
                              ]
                      }, 
                      {:pupil_calls=&gt;"0"}, 
                      {:returned_calls=&gt;[
                                         {"from_number"=&gt;"447952xxxxxx", "to_number"=&gt;"447440xxxxxx", "type"=&gt;"call", "duration"=&gt;50, "direction"=&gt;"outbound"}, 
                                         {"from_number"=&gt;"447952xxxxxx", "to_number"=&gt;"447440xxxxxx", "type"=&gt;"call", "duration"=&gt;nil, "direction"=&gt;"outbound"}
                                         ]
                      }
                     ] 
    },
    {"447588xxxxxx"=&gt;[
                        {:cbrs=&gt;"0"}, 
                        {:pupil_calls=&gt;[
                                         {"from_number"=&gt;"447588xxxxxx", "to_number"=&gt;"441483xxxxxx", "type"=&gt;"call", "duration"=&gt;5, "direction"=&gt;"inbound"}
                                        ]
                        }, 
                        {:returned_calls=&gt;"0"}
                      ]
    }
  ]
  </code></pre>
  
  <p>In my view I am trying to do this sort of thing </p>
  
  <pre><code>&lt;% array.each do |a| %&gt;
  
  &lt;%= a.first_key %&gt; #this is the number at the start each group eg 447478xxxxxx`
  
  &lt;% a.cbrs.each do |c| %&gt;
  
     &lt;%=c.type%&gt; #for example, this is just limited sample of the scope of the data
  
  &lt;%end%&gt;
  
  &lt;% a.pupil_calls.each do |c| %&gt;
  
     &lt;%=c.from_number%&gt; - &lt;%=c.to_number%&gt; 
  
  &lt;%end%&gt;
  
  &lt;% a.returned_calls.each do |c| %&gt;
  
     &lt;%=c.duration%&gt;
  
  &lt;%end%&gt;
  
  &lt;%end%&gt;
  </code></pre>
  
  <p>But I don't know how to go about accessing the values contained within the hashes within the arrays within the hashes within the array! (Think I got that right.)</p>
  
  <p>Edit: What I'm after is simple enough - I just want to be able to do something like this for each item in array:</p>
  
  <pre><code> Tel: 447478xxxxxx 
   CBRS: 1 
   Calls: 0
   Returned: 0
  
   Tel: 447440xxxxxx
   CBRS: 1
   Calls: 0
   Returned Calls: 2 
   Call first returned about 5 minutes after CBR #This would be using created_at dates for example, there is a lot of info I didn't include in my sample data.   
   Returned Call 1: recording link
   Returned Call 2: recording link
  </code></pre>
  
  <p>Hope that helps, I just wrote out the output without html etc. The above would be as a result of looping through array of hashes and for each hash looping through it ...</p>