pry / pry-rails

Rails >= 3 pry initializer
MIT License
1.35k stars 88 forks source link

Pry not starting after installing pry-rails #97

Open thestrabusiness opened 7 years ago

thestrabusiness commented 7 years ago

I'm trying to include pry-rails in a Rails 5 app using Ruby 2.4.1, but it doesn't seem to replace irb in the console.

I've included pry-rails in my gemfile and run bundle install, but when I start the console it still uses irb. I tried moving it out of the development group, but that made no change. Am I missing a step here? Thanks in advance.

Gemfile:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

ruby '2.4.1'

gem 'aws-sdk'
gem 'bootstrap-sass'
gem 'celluloid-io'
gem 'dotenv-rails'
gem 'inline_svg'
gem 'jbuilder', '~> 2.5'
gem 'jquery-rails'
gem 'metainspector'
gem 'monban'
gem 'newrelic_rpm'
gem 'otr-activerecord'
gem 'paperclip'
gem 'pg'
gem 'puma', '~> 3.0'
gem 'pundit'
gem 'rails', '~> 5.0.2'
gem 'sass-rails', '~> 5.0'
gem 'slack-ruby-bot-server'
gem 'turbolinks', '~> 5'
gem 'uglifier', '>= 1.3.0'

group :development do
  gem 'better_errors'
  gem 'listen', '~> 3.0.5'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'web-console', '>= 3.3.0'
end

group :development, :test do
  gem 'pry-rails'
  gem 'binding_of_caller'
  gem 'railroady'
end

group :test do
  gem 'capybara-webkit'
  gem 'database_cleaner'
  gem 'factory_girl_rails'
  gem 'rspec-rails'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Gemfile.lock shows pry and pry-rails:

pry (0.10.4)
pry-rails (0.3.6)
  pry (>= 0.10.4)
mswieboda commented 7 years ago

I'm having a similar issue, Rails 5.1.2 ruby 2.3.4, fresh installs today.

I can't even do require 'pry' from rails console once it loads IRB. Which is why I imagine it's failing:

irb(main):001:0> require 'pry'
LoadError: cannot load such file -- pry
    from (irb):1

Maybe it's something with Rails 5? I'm more familiar with Rails 4, which I've had no pry problems, and have loaded pry using `~/.irbrc via https://github.com/pry/pry/wiki/Setting-up-Rails-or-Heroku-to-use-Pry#with-irbrc-file.

anaumov commented 7 years ago

Same problem here with rails 5. Even can't require 'pry' in console

UPD: it just works now. May be new rails works well.

thromera commented 7 years ago

Same issue with Rails 5.1.2, ruby 2.4.1p111 :(.

alexdilley commented 7 years ago

Find it works if you DISABLE_SPRING:

$ DISABLE_SPRING=1 bin/rails c
Loading development environment (Rails 5.1.4)
[1] pry(main)>

🙄

0x1eef commented 7 years ago

This comment won't help.. but check out some of the alternative web frameworks so Ruby on Rails doesn't have such an iron grip influence on the available options in the professional Ruby space. I feel sorry for people caught up in DHH-ism and I think a backlash is inevitable, because there is never one 'One Right Way' and having an opinionated framework is fine, if other opinions can breath and excel as well. My two cents.

dennyluan commented 6 years ago

Unfortunately, the disable_spring option doesn't work for me in rails 5.0.6.

0x1eef commented 6 years ago

@rf- can you look into this if you have time? or @kyrylo neither banister nor myself use rails and i don't have the motivation to look into it. otherwise a third party contributor will have to step up to solve the issue.

karuppasamy commented 6 years ago

I don't see any issues.

demoapp$ rails -v
Rails 5.1.4
demoapp$ ruby -v
ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-darwin17]
demoapp$ rails c
Running via Spring preloader in process 82783
Loading development environment (Rails 5.1.4)
[1] pry(main)>
PrimeTimeTran commented 6 years ago

A little bit off topic but do you guys ever have problems with pry working on Ajax requests?

Pry doesn't stop on Ajax requests and simply prints to the screen and then the request continues. Sorry if this is a newb question!

screen shot 2018-01-02 at 2 38 20 am

mswieboda commented 6 years ago

@PrimeTimeTran use Chrome debugger for AJAX, pry Rails. If you need pry for AJAX, then you can try pry-remote that might help, I've used that in the past for asynchronous requests, like redis, sidekiq, etc.

argent-codes commented 3 years ago

EDIT: Turns out I was using an older version of this gem, 0.3.6. Upgrading to 0.3.9 fixed the issue for me (though the warnings on the bottom are still there).

It looks like this project hasn't been updated in some time, but I ran into this (or a similar) issue after going to Rails 6, and was seemingly able to fix it by updating my application.rb with something similar to what this gem does:

class Application < Rails::Application
  config.console = Pry
  # the rest of my config here...
end

Or, more accurately, I updated my config/environments/development.rb with

require 'pry'

Rails.application.configure do
  config.console = Pry
  # ...
end

I am getting some warnings when fire up the console:

<main>: warning: __FILE__ in eval may not return location in binding; use Binding#source_location instead
/Users/ekirilov/.gem/ruby/2.7.2/gems/pry-byebug-3.6.0/lib/pry-byebug/base.rb:9: warning: in `eval'
/Users/ekirilov/.gem/ruby/2.7.2/gems/pry-byebug-3.6.0/lib/pry-byebug/pry_ext.rb:11: warning: __FILE__ in eval may not return location in binding; use Binding#source_location instead
/Users/ekirilov/.gem/ruby/2.7.2/gems/pry-stack_explorer-0.4.9.2/lib/pry-stack_explorer/when_started_hook.rb:63: warning: in `eval'
/Users/ekirilov/.gem/ruby/2.7.2/gems/railties-6.0.3.5/lib/rails/commands/console/console_command.rb:70: warning: __FILE__ in eval may not return location in binding; use Binding#source_location instead
/Users/ekirilov/.gem/ruby/2.7.2/gems/pry-stack_explorer-0.4.9.2/lib/pry-stack_explorer/when_started_hook.rb:63: warning: in `eval'

Frame number: 0/9
<main>: warning: __FILE__ in eval may not return location in binding; use Binding#source_location instead
/Users/ekirilov/.gem/ruby/2.7.2/gems/pry-0.11.3/lib/pry/commands/whereami.rb:41: warning: in `eval'
<main>: warning: __LINE__ in eval may not return location in binding; use Binding#source_location instead
/Users/ekirilov/.gem/ruby/2.7.2/gems/pry-0.11.3/lib/pry/commands/whereami.rb:42: warning: in `eval'

So it's possible that I'll still run into issues down the line, but this at least allows me use the pry console helpers I have defined in my .pryrc.

technicalpickles commented 2 years ago

I suspect some of the problems reported here have to do with spring. More recent versions of spring should be handling restarting when things like the Gemfile change, so I don't expect it to be a problem anymore.