# Puts just work on Controllers

**URL:** <https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820>\
**Category:** Rails\
**Created:** [July 9, 2009, 6:37pm UTC](https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820 "2009-07-09T18:37:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 9, 2009, 6:37pm UTC](https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820/1 "2009-07-09T18:37:24Z")

</div>

Hi you all,  
I am trying to put some statements out to console in my Rails app, for  
debugging purposes, especially in the model classes. However, they do  
not work at all. I am trying with p, puts, print, but nothing. I just  
get it working when this statements are in a controller, but not in  
model classes.

I’ve also tried with  
Rails.logger.debug(“whatever”)

but nothing, this also works only in the controller.

What can I do? ☹  
I’m working with Jruby 1.1.6 and Rails 2.1.2 in a Webrick server.

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 9, 2009, 6:43pm UTC](https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820/2 "2009-07-09T18:43:06Z")

</div>

Well, there are a few different ways to debug your app. What are you  
trying to find out?

In the model you can put:

class ModelName \< ActiveRecord::Base  
puts caller

…  
…  
end

That will give you the call stack everytime the model is hit.

If you want to debug params within your views you can place:

\<%= debug params %\>

Which will list all of the params in your views…

The list goes on and on…

What do you need to check?

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 9, 2009, 7:01pm UTC](https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820/3 "2009-07-09T19:01:56Z")

</div>

It is just I want to see objects attributes I have from my model classes  
in the output, this is why I do the “puts” or “p”, but it does not work.  
For example, I have a SearchEngine class, I have a def search() function  
that returs some results, and I want to see these results before sending  
them to the controller…

Ã„lphÃ¤ BlÃ¼Ã« wrote:

> Well, there are a few different ways to debug your app. What are you  
> trying to find out?
> 
> In the model you can put:
> 
> class ModelName \< ActiveRecord::Base  
> puts caller
> 
> …  
> …  
> end
> 
> That will give you the call stack everytime the model is hit.
> 
> If you want to debug params within your views you can place:
> 
> \<%= debug params %\>
> 
> Which will list all of the params in your views…
> 
> The list goes on and on…
> 
> What do you need to check?

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 9, 2009, 7:21pm UTC](https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820/4 "2009-07-09T19:21:31Z")

</div>

You should debug through test parameters. Here’s a site link to help:

> **[Five tips for testing Rails](https://www.thechrisoshow.com/2008/05/04/five-tips-for-testing-rails/)**
>
> Tip One – Debugging tests
> I use RDebug in my apps a lot, but frequently I found myself wanting to debug my
> tests. Here’s how you can do it:
> 
> If you haven’t done so already, install RDebug
> $ gem install ruby-debug
> 
> 
> Insert debugger in your code where...

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 10, 2009, 7:47pm UTC](https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820/5 "2009-07-10T19:47:52Z")

</div>

On Jul 10, 5:33 am, Damaris F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Ok, I will take a look to these ways for debug.  
> However, I still don’t understand why my “puts” don’t work.  
> My non-Active record models are not in the app/model directory, but in  
> an app/engine directory (is someone else work), can be this the problem?

Where are you looking for the output of the controller puts? Assuming  
that you are running your Rails test server using script/server then  
that information is displayed on the server console.

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 10, 2009, 11:33am UTC](https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820/6 "2009-07-10T11:33:32Z")

</div>

Ok, I will take a look to these ways for debug.  
However, I still don’t understand why my “puts” don’t work.  
My non-Active record models are not in the app/model directory, but in  
an app/engine directory (is someone else work), can be this the problem?  
Or can be something related with jruby?

Ã„lphÃ¤ BlÃ¼Ã« wrote:

> You should debug through test parameters. Here’s a site link to help:
> 
> [Five tips for testing Rails](http://www.thechrisoshow.com/2008/5/4/five-tips-for-testing-rails)

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 11, 2009, 1:29pm UTC](https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820/7 "2009-07-11T13:29:50Z")

</div>

On the server console.  
I run the server by means of “jruby script/server”, in development mode.  
At the server console just appears the information of the HTTP requests.

James B. wrote:

> On Jul 10, 5:33ï¿½am, Damaris F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Ok, I will take a look to these ways for debug.  
> > However, I still don’t understand why my “puts” don’t work.  
> > My non-Active record models are not in the app/model directory, but in  
> > an app/engine directory (is someone else work), can be this the problem?
> 
> Where are you looking for the output of the controller puts? Assuming  
> that you are running your Rails test server using script/server then  
> that information is displayed on the server console.

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 11, 2009, 1:37pm UTC](https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820/8 "2009-07-11T13:37:02Z")

</div>

Taking a look through Google I found that some people have the same  
problem, but most of them because they have changed from Webrick to  
Mongrel. Apparently, console with mongrel does not show the “puts”  
messages. However, I am working with webrick.  
Damaris F. wrote:

> On the server console.  
> I run the server by means of “jruby script/server”, in development mode.  
> At the server console just appears the information of the HTTP requests.
> 
> James B. wrote:
> 
> > On Jul 10, 5:33ï¿½am, Damaris F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > wrote:
> > 
> > > Ok, I will take a look to these ways for debug.  
> > > However, I still don’t understand why my “puts” don’t work.  
> > > My non-Active record models are not in the app/model directory, but in  
> > > an app/engine directory (is someone else work), can be this the problem?
> > 
> > Where are you looking for the output of the controller puts? Assuming  
> > that you are running your Rails test server using script/server then  
> > that information is displayed on the server console.

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [August 20, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/puts-just-work-on-controllers/171820/9 "2009-08-20T22:45:28Z")

</div>

Damaris F. wrote:

> Taking a look through Google I found that some people have the same  
> problem, but most of them because they have changed from Webrick to  
> Mongrel. Apparently, console with mongrel does not show the “puts”  
> messages. However, I am working with webrick.

I’m getting the same issue, and I’m using lightppd. Way back I had some  
simple output to console type of thing, and I’m sure at the time I used  
print. That would have been on webrick back then.

I’m going to follow this thread as I’d like to know what the trick is. I  
fI find out before you, I’ll post back.
