Ruby rails - using 'p' to print causes errors

software development

#1

When I use the standard print mechanism for Rails, .fcgi and .cgi throw errors. When run from the webrick server, no issues. Webrick writes it to the console, while .cgi writes it to standard out.

Any ideas?

I’m about to switch my code to use the logger instead of “p”.


#2

Well, that’s definitely the problem.

During development I made use of puts and p (the stdout printing functions) to output to the console that WebBrick runs in for general tracing and debugging.

However, this goes right to the browser when using CGI and FCGI. So, don’t do it. Use the Logger.

But, getting around it is possible:
http://www.ruzee.com/blog/2006/11/redirecting-stdout-to-logger-with-ruby-on-rails/