# Retrieving hashes key & values (ASAP)

**URL:** <https://www.ruby-forum.com/t/retrieving-hashes-key-values-asap/60521>\
**Category:** Rails\
**Created:** [May 15, 2006, 9:08am UTC](https://www.ruby-forum.com/t/retrieving-hashes-key-values-asap/60521 "2006-05-15T09:08:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshua-asem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshua-asem](https://www.ruby-forum.com/u/joshua-asem)\
**Post date:** [May 15, 2006, 9:08am UTC](https://www.ruby-forum.com/t/retrieving-hashes-key-values-asap/60521/1 "2006-05-15T09:08:47Z")

</div>

Hi,  
I want to retrieve the set of key & values which returns from a  
stored procedure : connection.select\_all "exec common.dbo.scr\_lookupric  
‘AAP.N’ ".

The results i want to display in a view screen call result.rhtml.  
Please help me out ASAP.

Thanks in advance.  
joshua…

---

<div class="post-metadata">

**Author:** ![joshua-asem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshua-asem](https://www.ruby-forum.com/u/joshua-asem)\
**Post date:** [May 15, 2006, 2:11pm UTC](https://www.ruby-forum.com/t/retrieving-hashes-key-values-asap/60521/2 "2006-05-15T14:11:59Z")

</div>

connection.select\_all gives you an array of hashes which map  
column\_name =\> value. In the controller:

def view  
@rows = ActiveRecord::Base.connection.select\_all(“exec common …”)  
end

And a very basic view.rhtml:

\<% @rows.each do |row|  
row.each do |key, value|  
%\>  
\<%= key %\>: \<%= value %\>  
  
\<% end  
end %\>

-Jonathan.

---

<div class="post-metadata">

**Author:** ![joshua-asem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshua-asem](https://www.ruby-forum.com/u/joshua-asem)\
**Post date:** [May 15, 2006, 3:18pm UTC](https://www.ruby-forum.com/t/retrieving-hashes-key-values-asap/60521/3 "2006-05-15T15:18:49Z")

</div>

Thanks a lot Jonathan… !!

I am able to access those key values properly now.  
But one doubt is : Is there any way of accessing those values with the  
key.

Something like: valuesOf(key1);

Now i am storing like this in one-one variable to refer further in the  
view page. Pls suggest me as the following is little bit redundant.

# =================================== \<% @rows.each do |row| row.each do |key, value| %\> \<% if key==‘secid’ %\> \<% @secid=value %\>\<% end %\> \<% if key==‘ric’ %\>\<% @ric=value %\> \<% end %\> \<% end end %\>

Thanks in advance…

1. Also I have one issue for setting the table name : “CR\_Country”

One issue is there in connecting one schema(table) “CR\_Country” and  
“CR\_Security” from this sybase Db.

# I have set false for pluralize\_table\_name and also setting the table name explicitly too as follow in the “environment.rb” :

ActiveRecord::Base.pluralize\_table\_names = false

# class CR\_Country \< ActiveRecord::Base set\_table\_name “CR\_Country” end.

Now it gives an error as

not able to find object “select \* from cR\_Country”

and another one as :  
not able to find object “select \* from cr\_security”

It somewhere converted the table name to small letters. Please help me  
out if you have any suggestion.

Thanks in advance,  
Joshua…
