Forum: Ruby on Rails SQL in rails

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.
F2b6d7bf3a3d324a5d0fb4894923d372?d=identicon&s=25 xxmithila (Guest)
on 2008-10-29 14: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..

thankx
6fabb84e727dee98d1277df56458cbac?d=identicon&s=25 Andrew Bloom (Guest)
on 2008-10-29 15:07
(Received via mailing list)
class Model < ActiveRecord::Base
  def raw_sql_query
    connection.execute("select name from #{table_name}")
  end
end

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