Search code examples
ruby-on-railsrubydebuggingconsolepdb

Interactive Shell for Ruby on Rails


When working on a web app in python/flask, I am able to import pdb at the top of a file, and then call pdb.set_trace() somewhere in my code to "pause" the web app and open an interactive console in my terminal for debugging. I am looking for something similar in Ruby/Rails. What exists for this purpose, and how do I use it?


Solution

  • I have found a solution.

    The gem debugger is created for this purpose. To start, run

    gem install debugger
    

    After, add the line debugger into your code to "pause" the code at that point. For example:

    def hello
        @users = Users.all()
        debugger
    end
    

    Then, when starting the server, call it with:

    rails server --debugger