thewillcole
thewillcole

Reputation: 3045

Why won't Pry run in Heroku's console?

My goal is to use Pry as the console for my Rails app, both locally and on my staging server. But I can't get it to work on Heroku.

I'm following these instructions to get Heroku to use Pry as the console for my Rails app. When I run heroku run console pry, my console prints Running console pry attached to terminal... up, run.1 and then exits. When I run heroku console pry it just says main and then exits.

Any ideas on what I'm doing wrong?

Here's what I've done so far:

  1. In my Gemfile I've added the lines:
    gem 'pry'
    gem 'pry-rails'

  2. I've created a file called pry which contains:
    #!/usr/bin/env ruby
    require 'pry'
    pry

  3. I added the following to all the files in config/environments:
    silence_warnings do
    begin
    require 'pry'
    IRB = Pry
    rescue LoadError
    end
    end

  4. run bundle install

  5. run git push staging master

Upvotes: 8

Views: 3646

Answers (3)

Jordon Bedwell
Jordon Bedwell

Reputation: 3247

I am the one who developed the method for Heroku and Pry but you brought up an interesting case that I didn't think about since I mostly deploy with Sinatra and EM and build my own helpers and such. Either way:

To use Pry with Heroku while having a Rails app you just need to add pry-rails and pry to your gemfile (as a normal Gem) and then bundle install and then git [commit|push] and run heroku run console on Cedar stack. Step 3 of what you did where you adjusted config/environments does not and should not be done so please revert that change if you can. After you do that and remove the pry script from the root of your app (well you don't necessarily need to do the latter) Pry will load with your Rails properly.

Upvotes: 14

John Beynon
John Beynon

Reputation: 37507

I've just used the instructions at https://github.com/pry/pry/wiki/Setting-up-Rails-or-Heroku-to-use-Pry to set it up, pry file goes in the root of your project. Commit and push to Heroku - I'm using the Cedar stack.

Effect a console session to heroku run console pry - I did find that I did then need to execute pry to be dropped into a pry prompt but it then worked as I'd expect.

UPDATE: Just to be clear, I added pry to Gemfile and created the pry file as instructed. Is your problem that you are locking pry in your gemfile to dev/test - are you running your apps on Heroku in those environments? Hence why you're getting undefined methods?

Upvotes: 3

John Bachir
John Bachir

Reputation: 22751

You probably have to list it in your bundler Gemfile.

Upvotes: 0

Related Questions