0

I'm new to ruby on rails.

Can anyone suggest a debugging method for ruby on rails. (Like var_dump, print_r in php).

I saw debugger and ytml. could anyone explain how to use them?

2 Answers 2

3

Add in your Gemfile

gem 'debugger'

then bundle install.

Then use like this in methods

def index
  debugger       
  @files = Example.order('created_at DESC')
end

And in views(.erb) use like this.

<%debugger%>

This will cause debugger to break code execution and give you an interactive console on the line "debugger". You can type "step" to dive into the line of code or type "next" to stay at the same level and process the line you're on.

Typing "continue or c" will resume code execution until the next "debugger" line is encountered, if any

2
  • thanx,.. but.. while executing bundle install i'm facing "Gem::Ext::BuildError: ERROR: Failed to build gem native extension."
    – m2j
    May 25, 2015 at 12:26
  • The debugger gem isn't supposed to be used with ruby 2.0+, and literally won't install with ruby 2.1.2. You are going to have to switch to byebug. May 25, 2015 at 12:29
1

I would suggest you look into pry, a debugging REPL you can use inside of rails. For other cases, there's the rails console command, which will allow you to open up a REPL in the context of your running application in development mode, and should be sufficient for most development needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.