I have a view for displaying the contents of a Mongoid document. When it iterates through an array of hashes, it displays the key values pairs as desired but then it dumps the contents of the raw hash unexpectedly. Can anyone explain this behavior?
Here is the view code (in haml);
- @account.attributes.keys.each do |key|
- if @account[key].class == Array
%b= key.humanize
%br
- @account[key].each do |key2|
= key2.each do |key3,value|
#{key3.humanize}: #{value}
%br
%br
Here is an embedded collection from the mongo record to be displayed;
"sales" : [
{ "sale_date" : Date( 1256882400000 ),
"sale_price" : 210000,
"recording_no" : "2009085729" },
{ "sale_date" : Date( 1160719200000 ),
"sale_price" : 268300,
"recording_no" : "2006088793" } ],
Here is what shows up in the rendered page;
Sales
Sale date: 2009-10-30 06:00:00 UTC
Sale price: 210000
Recording no: 2009085729
{“sale_date”=>2009-10-…006-10-13 06:00:00 UTC
Sale price: 268300
Recording no: 2006088793
{“sale_date”=>2006-10-…ing_no”=>”2006088793”}
Notice the last line of each sale contains the entire hash again! Any clue why?
Change
= key2.eachto- key2.each.