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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
May be can try this: @t.map do |k| k.attributes.values end # return [[value1, value2, value3], [value1, value2, value3] ...] Herry -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Bryce Sent: 04 April 2007 09:30 To: Ruby on Rails: Talk Subject: [Rails] attribute_names and/or values? 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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? On Apr 3, 6:44 pm, "Herryanto Siatono" <herrya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> May be can try this: > > @t.map do |k| > k.attributes.values > end > > # return [[value1, value2, value3], [value1, value2, value3] ...] > > Herry > > -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Bryce > Sent: 04 April 2007 09:30 > To: Ruby on Rails: Talk > Subject: [Rails] attribute_names and/or values? > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---