# Active record outside of rails

**URL:** <https://www.ruby-forum.com/t/active-record-outside-of-rails/50413>\
**Category:** Rails\
**Created:** [December 16, 2005, 1:41am UTC](https://www.ruby-forum.com/t/active-record-outside-of-rails/50413 "2005-12-16T01:41:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [December 16, 2005, 1:41am UTC](https://www.ruby-forum.com/t/active-record-outside-of-rails/50413/1 "2005-12-16T01:41:25Z")

</div>

I really like how Active Record logs the SQL that is executed inside of  
rails. Is there a way to get the SQL output when using Active Record  
outside of rails?

Thanks,

phil

---

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [December 16, 2005, 1:48am UTC](https://www.ruby-forum.com/t/active-record-outside-of-rails/50413/2 "2005-12-16T01:48:10Z")

</div>

try google on the very title of your message

```
http://www.google.com/search?q=activerecord%20outside%20of%20rails

```

You’ll be amazed by the result.

[http://www.cultkanaal.nl/Tech/google-bart.jpg](http://www.cultkanaal.nl/Tech/google-bart.jpg)

Alain

---

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [December 16, 2005, 1:04pm UTC](https://www.ruby-forum.com/t/active-record-outside-of-rails/50413/3 "2005-12-16T13:04:53Z")

</div>

Alain R. wrote:

> try google on the very title of your message
> 
> ```
> http://www.google.com/search?q=activerecord%20outside%20of%20rails
> 
> ```
> 
> You’ll be amazed by the result.

Really? It doesn’t obviously contain the answer to the OP’s question  
(which was about how to log the SQL when using AR outside of Rails)

---

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [December 16, 2005, 1:53pm UTC](https://www.ruby-forum.com/t/active-record-outside-of-rails/50413/4 "2005-12-16T13:53:22Z")

</div>

> Really? It doesn’t obviously contain the answer to the OP’s  
> question  
> (which was about how to log the SQL when using AR outside of Rails)

I reacted on the title and the main sentence that says “… a way to get  
SQL output…” (SQL output = result, not log). I guess that Phil wants  
the “logged SQL commands”, and not the “SQL output”.

I Should have noticed the ambiguity of the message. My bad.

Alain

---

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [December 16, 2005, 2:53pm UTC](https://www.ruby-forum.com/t/active-record-outside-of-rails/50413/5 "2005-12-16T14:53:41Z")

</div>

Thank you very much! I guess I need to start digging in to the  
rails/active  
record source so I can figure this stuff out…

phil

---

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [December 16, 2005, 2:17pm UTC](https://www.ruby-forum.com/t/active-record-outside-of-rails/50413/6 "2005-12-16T14:17:23Z")

</div>

On 16-dec-2005, at 1:39, Phil S. wrote:

> I really like how Active Record logs the SQL that is executed  
> inside of rails. Is there a way to get the SQL output when using  
> Active Record outside of rails?

require ‘rubygems’  
require ‘active\_record’

ActiveRecord::Base.logger = Logger.new(File.dirname( **FILE** ) + “/  
debug.log”)

ActiveRecord::Base.establish\_connection(hash\_of\_params)

–  
Julian ‘Julik’ Tarkhanov  
me at julik.nl

---

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [December 22, 2005, 9:31am UTC](https://www.ruby-forum.com/t/active-record-outside-of-rails/50413/7 "2005-12-22T09:31:48Z")

</div>

Phil,

I owe you an apology.

Alain R. wrote:  
\> try google on the very title of your message  
I was wrong.

> [http://www.cultkanaal.nl/Tech/google-bart.jpg](http://www.cultkanaal.nl/Tech/google-bart.jpg)  
> And I was rude.

Please excuse me.

Alain
