ohho ohho - 1 year ago 85
SQL Question

How to access Mysql::Result in ActiveRecord?


result = ActiveRecord::Base.connection.execute("select 'ABC'")

How can I get the
value from
? Tried
without success. Thanks

p.s. Gems:

activerecord (2.3.9)

mysql (2.8.1)

Answer Source

You could try it on the cosole:

script/console # rails 2
rails console  # rails 3

enter your code in the console and you get:

irb> result = ActiveRecord::Base.connection.execute("select 'ABC'")
 => [{0=>"ABC", "'ABC'"=>"ABC"}] 

so it you get it with

# or

result.first just returns the first row, not the first value. This row consists of a Hash with numerical and named access.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download