0

Trying to get rails debugger work. I did following:

gem install debugger

Added in Gemfile

gem "debugger", "~> 1.2.0"

bundle install - no error

Now I put debugger in one of my controllers

def show
    require 'debugger'; debugger
    @user = User.find(params[:id])

    respond_to do |format|
       format.html # show.html.erb
       format.json { render json: @user }
    end
end

When I point my browser, I get following error on browser

LoadError in UsersController#show

cannot load such file -- debugger

I am using ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] and Rails 3.2.6 with Phusion passenger

Any idea what is wrong?

JVK
  • 3,782
  • 8
  • 43
  • 67

2 Answers2

0

Remove require statement and start rails server with debugger option

rails server --debugger

abhilash
  • 71
  • 3
0

Not exactly sure how you want to use the debugger gem, but it is great for creating stop-points in active code. In Rails 3, you only need in your routes.rb:

gem 'debugger'

It doesn't have any effect in production and to have it stop your code at any point, simply put 'debugger' and your server console will give you access to that point in your code. At that point, to check the status of variables, you need to access IRB, so just type in 'irb'. In your 'show' action, you can check the value of your params and whether @user would be populated.

def show
  debugger
  @user = User.find(params[:id])
  ...
Carson Cole
  • 4,183
  • 6
  • 25
  • 35
  • Did you say I need to put this "gem 'debugger'" in routes.rb? or Gemfile? I am running Nginx with Phusion passenger, so do I need to start rail server? – JVK Aug 28 '12 at 16:58
  • As my comment says, put the gem line in your routes. And yes, you should probably do 'bundle install' in your console, and then restart. – Carson Cole Aug 28 '12 at 18:54