Search code examples
rubysinatrapry

Using pry with Sinatra


New to Ruby and Sinatra.

I'm trying to use pry within a Sinatra controller (want to be able to take a look at what params is returning to me). I added a 'binding.pry' inside of the Post request, but it's not working. I know I need to require 'pry' but should that be placed in the controller file, config.ru or environment file in order to work properly? Thanks!


Solution

  • It all depends on where you want to use pry. If you want it to work everywhere in your Sinatra project, then just add it to your Gemfile.

    group :development, :test do
       gem 'pry'
    end
    

    I would recommend limiting the environments to :development and :test, since you will be doing your debugging there.

    You can also require it in the top of your application like so:

    require 'pry'