[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

hash of hashes group_by

Dave Smith

6/5/2009 1:44:00 PM

Hi Guys,

I have the following code which grabs some data from the database in my
model

def get_stats
sql = "select id, value from table"
my_data = self.class.connection.select_all(sql)
my_data.group_by { |row| row[:id] }
end

the data is clearly in there as a puts shows

value4id1
value1id2

but when trying to access the values

x = my_data[1][:value]

The error occurred while evaluating nil.[]

Can anyone shed some light on this?

Cheers
--
Posted via http://www.ruby-....

1 Answer

Brian Candler

6/5/2009 3:06:00 PM

0

Try 'p xxx' (or 'puts xxx.inspect') instead of 'puts xxx'.

This will show you things like the difference between a string and a
number, or between an empty string and nil.
--
Posted via http://www.ruby-....