I'm in an array & hash rabbit hole, please excuse verbose question.
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:
[ {"447478xxxxxx"=>[ {:cbrs=>[ {"telephone_number"=>"447478xxxxxx", "type"=>"cbr"} ] }, {:pupil_calls=>"0"}, {:returned_calls=>"0"} ] }, {"447440xxxxxx"=>[ {:cbrs=>[ {"telephone_number"=>"447440xxxxxx", "type"=>"cbr"} ] }, {:pupil_calls=>"0"}, {:returned_calls=>[ {"from_number"=>"447952xxxxxx", "to_number"=>"447440xxxxxx", "type"=>"call", "duration"=>50, "direction"=>"outbound"}, {"from_number"=>"447952xxxxxx", "to_number"=>"447440xxxxxx", "type"=>"call", "duration"=>nil, "direction"=>"outbound"} ] } ] }, {"447588xxxxxx"=>[ {:cbrs=>"0"}, {:pupil_calls=>[ {"from_number"=>"447588xxxxxx", "to_number"=>"441483xxxxxx", "type"=>"call", "duration"=>5, "direction"=>"inbound"} ] }, {:returned_calls=>"0"} ] } ] In my view I am trying to do this sort of thing
<% array.each do |a| %> <%= a.first_key %> #this is the number at the start each group eg 447478xxxxxx` <% a.cbrs.each do |c| %> <%=c.type%> #for example, this is just limited sample of the scope of the data <%end%> <% a.pupil_calls.each do |c| %> <%=c.from_number%> - <%=c.to_number%> <%end%> <% a.returned_calls.each do |c| %> <%=c.duration%> <%end%> <%end%> 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.)
Edit: What I'm after is simple enough - I just want to be able to do something like this for each item in array:
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 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 ...
<% array.each do |a| %> <%= a.first_key %> <% a.cbrs.each do |c| <%=c.type%> <%end%>Ie the output would be447478xxxxxx cbr