Forum: Ruby on Rails retrieving hashes key & values (ASAP)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7a5f8cc44b8b6da7a415a2c5bcdc14be?d=identicon&s=25 Joshua Asem (joshua-asem)
on 2006-05-15 09:08
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...
631d1677786f0725da6ccee46043686e?d=identicon&s=25 Jonathan Viney (Guest)
on 2006-05-15 14:11
(Received via mailing list)
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 %><br />
<% end
end %>

-Jonathan.
7a5f8cc44b8b6da7a415a2c5bcdc14be?d=identicon&s=25 Joshua Asem (joshua-asem)
on 2006-05-15 15:18
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...


2) 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........
This topic is locked and can not be replied to.