# Outputting SQL to page

**URL:** <https://www.ruby-forum.com/t/outputting-sql-to-page/204310>\
**Category:** Rails\
**Created:** [March 9, 2011, 5:01pm UTC](https://www.ruby-forum.com/t/outputting-sql-to-page/204310 "2011-03-09T17:01:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 9, 2011, 5:01pm UTC](https://www.ruby-forum.com/t/outputting-sql-to-page/204310/1 "2011-03-09T17:01:00Z")

</div>

Hi,

I’m interested in just outputting the SQL from a AR find() construct to  
the page - without having to look at the console. I tried doing this:

self.joins(…)  
.select(…)  
.where(…)  
.order(…)  
.to\_s

thinking that it would output the sql as a string, but its just an AR  
object apparently. (note - I removed the particulars of the query for  
this example but they work fine and the query is visible in the  
console).

Any ideas? Newbie, obviously and working _really_ hard to embrace  
non-hand coded SQL. 🙂

Thanks!

Peter

---

<div class="post-metadata">

**Author:** ![Peter\_D\_Bethke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e495f1/32.png) [@Peter\_D\_Bethke](https://www.ruby-forum.com/u/Peter_D_Bethke)\
**Post date:** [March 9, 2011, 5:08pm UTC](https://www.ruby-forum.com/t/outputting-sql-to-page/204310/2 "2011-03-09T17:08:30Z")

</div>

On Wed, Mar 9, 2011 at 7:32 AM, Peter D Bethke [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m interested in just outputting the SQL from a AR find() construct to the page

- without having to look at the console.

Take a look at this gem:

[http://wiki.github.com/josevalim/rails-footnotes](http://wiki.github.com/josevalim/rails-footnotes)

Handy for a number of reasons 🙂

–  
Hassan S. ------------------------ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![Peter\_D\_Bethke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e495f1/32.png) [@Peter\_D\_Bethke](https://www.ruby-forum.com/u/Peter_D_Bethke)\
**Post date:** [March 10, 2011, 12:55am UTC](https://www.ruby-forum.com/t/outputting-sql-to-page/204310/3 "2011-03-10T00:55:56Z")

</div>

On Wed, Mar 9, 2011 at 11:32 PM, Peter D Bethke  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> 

use .to\_sql

> –  
> You received this message because you are subscribed to the Google G.  
> “Ruby on Rails: Talk” group.  
> To post to this group, send email to [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).  
> To unsubscribe from this group, send email to  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–
