Hi rubyists, I'm clunking around with this problem. I want to return an array of values from each record in my database table. I have this so far: @t = Table.find(:all) @t.each do |k| k.attributes end the method attributes returns a hash and attribute_names returns an array or the keys. Is there a method that returns an array of the values? Thanks, Bryce
on 2007-04-04 03:30
on 2007-04-04 03:45
May be can try this: @t.map do |k| k.attributes.values end # return [[value1, value2, value3], [value1, value2, value3] ...] Herry
on 2007-04-04 20:05
Thanks a lot, the code worked great after a couple of tweaks to the code above it. Any reason that @t.map do |k| k.attributes.values end works and @t.each do |k| k.attributes.values end (map vs. each) doesn't work?