Hello, I''m trying to get the column names associated w/ this record set: account_all = Account.find(:all) Since account_all is an array - how do I get the names? I know there''s got to be a simple way to do this. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 3/2/07, Clem Rock <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello, > > I''m trying to get the column names associated w/ this record set: > > > account_all = Account.find(:all)Since account_all is an array - how do I get the names? account_all.first.attributes.keys ed --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The column names are a property of the model, in this case Account, so you
can try something like:
account_all = Account.find(:all)
account_all.each do |account|
for col in Account.content_columns
col.human_name: account.send(col.name)
end
end
Here''s a good example of handling columns/rows:
http://wiki.rubyonrails.org/rails/pages/HowToExportToExcel
Regards,
Dave
_______________________________
Information and Educational Technology
Kwantlen University College - 604-599-2120
"So powerful is the light of unity that it can illuminate the whole
earth." --Bahá''u''lláh
Clem Rock <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
Sent by: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
02/03/2007 09:26 AM
Please respond to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
cc
Subject
[Rails] Getting column names from a record set
Hello,
I''m trying to get the column names associated w/ this record set:
account_all = Account.find(:all)
Since account_all is an array - how do I get the names?
I know there''s got to be a simple way to do this.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> I''m trying to get the column names associated w/ this record set: > > > account_all = Account.find(:all) > > > Since account_all is an array - how do I get the names?Account.column_names -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Perfect - exactly what I wanted! Thanks! Ed Hickey wrote:> On 3/2/07, Clem Rock <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> >> Hello, >> >> I''m trying to get the column names associated w/ this record set: >> >> >> account_all = Account.find(:all) > > Since account_all is an array - how do I get the names? > > > > account_all.first.attributes.keys > > > ed-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---