/ rails

Getting Pry into rails console

Getting Pry into rails console.

First you should have Pry installed.
Add gem 'pry' and gem 'pry-doc' to your Gemfile.
pry-doc allows you to do show-doc File for example to reference documentation right in your console.


group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
  gem 'pry'
  gem 'pry-doc'

Then you need to add the following setup to development.rb.


    console do
      require "pry"
      config.console = Pry
      unless defined? Pry::ExtendCommandBundle
        Pry::ExtendCommandBundle = Module.new
      require "rails/console/app"
      require "rails/console/helpers"
      TOPLEVEL_BINDING.eval('self').extend ::Rails::ConsoleMethods

      config.action_controller.allow_forgery_protection = false
    config.action_controller.permit_all_parameters = true

The allow_forgery_protection and permit_all_parameters allows you to sign in a Devise user like this:

app.post('/users/sign_in', user: {email: 'abc@example.com', password: '123456'})

You can then access current_user like this:

Getting Pry into rails console
Share this