Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 598
thewillcole Avatar asked Jan 17 '12 20:01

thewillcole


2 Answers

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.

like image 86
Jordon Bedwell Avatar answered Oct 18 '22 22:10

Jordon Bedwell


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?

like image 45
John Beynon Avatar answered Oct 18 '22 21:10

John Beynon