# How to retrieve unknow attributes and values

**URL:** <https://www.ruby-forum.com/t/how-to-retrieve-unknow-attributes-and-values/122766>\
**Category:** Rails\
**Created:** [December 11, 2007, 10:53pm UTC](https://www.ruby-forum.com/t/how-to-retrieve-unknow-attributes-and-values/122766 "2007-12-11T22:53:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [December 11, 2007, 10:53pm UTC](https://www.ruby-forum.com/t/how-to-retrieve-unknow-attributes-and-values/122766/1 "2007-12-11T22:53:55Z")

</div>

Hello again,

I’m receiving, I think, a collection, and each element of the collection  
have some attributes and values, and all of them are the same.

Here is the result in a debug(@result)

- 5: PERIOD  
0: “1”  
period: PERIOD  
partner: PARTNER  
reporter: REPORTER  
6: INDICATORS  
1: REPORTER  
7: INDICATOR\_VALUE  
product: PRODUCT  
2: PARTNER  
indicator\_value: INDICATOR\_VALUE  
id: “1”  
3: PRODUCT  
flow: FLOW  
indicators: INDICATORS  
4: FLOW
- 5: “199952”  
0: “2”  
period: “199952”  
partner: EU27\_INTRA  
reporter: EU27  
6: VALUE\_IN\_EUROS  
1: EU27  
7: “70417621”  
product: “89011010”  
2: EU27\_INTRA  
indicator\_value: “70417621”  
id: “2”  
3: “89011010”  
flow: “1”  
indicators: VALUE\_IN\_EUROS  
4: “1”

This is what I have in the controller:

c = ActiveRecord::Base.connection  
@result = c.execute(params[:expert\_command])  
render :partial =\> “expert\_mode\_result”, :layout =\>false

I’m sending some SQL commands, and I don’t know what the user can enter,  
so I have to retrieve the attributes for creating the labels of the  
columns, and then the values of each attribute.

I’m using this \<%= @result.each {|key, value| puts “#{key} is #{value}”  
} %\> but I’m getting all the values and attributes for each element,  
and I can’t add

 etc. etc.

I’m reading the Ruby manual but still don’t know how to accomplish this  
…

thanks,

rai
