1

Are there simple ways to print debug strings in Rails? Something like the OutputDebugString() function in Windows.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Kichang Yang
  • 913
  • 2
  • 7
  • 11
  • Are you just looking for output to standard out? If so, you can always use "puts". Otherwise, I'm not sure what the OutputDebugString() command does - can you tell us more about what you're looking for? – Mark Tabler Feb 15 '12 at 22:41
  • It works with the small program called DbWin.exe. Basically, a special console dedicated to the debugging purpose. Debug string appears in DbWin's console window. – Kichang Yang Feb 15 '12 at 23:06
  • 'puts' works great with the functional test code. I didn't think the answer was so simple. – Kichang Yang Feb 15 '12 at 23:14

1 Answers1

2

http://guides.rubyonrails.org/debugging_rails_applications.html

"To write in the current log use the logger.(debug|info|warn|error|fatal) method from within a controller, model or mailer:"

logger.debug "Person attributes hash: #{@person.attributes.inspect}"
logger.info "Processing the request..."
logger.fatal "Terminating application, raised unrecoverable error!!!"

You could also use raise object.inspect.

Or, if you want more powerful debugging tool, take a look at pry: http://railscasts.com/episodes/280-pry-with-rails

binding.pry in your code and you'll be able to debug ALL THE THINGS!

Robin
  • 21,667
  • 10
  • 62
  • 85