Forum: Ruby on Rails SQL in rails

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
xxmithila (Guest)
on 2008-10-29 15:29
(Received via mailing list)
Hi all......

   please give me an example that use SQL in models to handel data in
the data base. with "sql.execute"  or any other possible way..

Andrew B. (Guest)
on 2008-10-29 16:07
(Received via mailing list)
class Model < ActiveRecord::Base
  def raw_sql_query
    connection.execute("select name from #{table_name}")

The above example will return something like this:
[{:name => "A"}, {:name => "B"}]
mithila karunarathna (Guest)
on 2008-10-29 18:49
(Received via mailing list)
thankx Andrew
I'll try it
This topic is locked and can not be replied to.