Running raw SQL command in Ruby on Rails

Sometimes you have to work with raw SQL in RoR for the better performance of your application. But how would you do it? Here’s a simple example on how to use raw SQL in RoR:


sql = "Select * from table"
records = ActiveRecord::Base.connection.execute(sql)

RoR devs, whats your take on this? any comments, suggestions, or ideas regarding raw SQL in RoR? I love to know. Let’s talk in the comment section.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s