write sql queries in rails controller code example Example: rails execute sql results = ActiveRecord::Base.connection.exec_query(sql)