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.

On 3/2/07, Clem R. [email protected] 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

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

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 R. [email protected]
Sent by: [email protected]
02/03/2007 09:26 AM
Please respond to
[email protected]

To
[email protected]
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/.

Perfect - exactly what I wanted!

Thanks!

Ed Hickey wrote:

On 3/2/07, Clem R. [email protected] 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