我对需要安装哪些 gem 才能在 Rails 4.2 项目中正确运行 Pry 感到困惑。直到最近我似乎都过得很好。出于某种原因,binding.pry
每当我尝试在命令行中使用 , 等单next
步执行控制台会话时,现在似乎都会吐出来。step
它会抛出一个丑陋的堆栈跟踪,然后在代码中显示相同的点,而无需进一步。在第二个next
命令之后,它抛出相同的堆栈跟踪并退出,将执行返回到 localhost 服务器。我在浏览器页面上收到运行时错误No frames collected
。
如果我在代码中注释掉binding.pry
,一切正常。所以我强烈怀疑我的 Pry 配置有问题。似乎有几十种 Pry 变体,没有明确的指导说明应该安装哪些,哪些可能会发生冲突等。
next
这是我在代码到达后在 Pry 控制台中调用时得到的堆栈跟踪binding.pry
:
From: /Users/me/sites/arailsapp/app/controllers/bars_controller.rb @ line 31 BarsController#edit:
29: def edit
30: binding.pry
=> 31: @bar = Bar.find(params[:id])
32: @foo = @bar.foo
33: end
[6] pry(#<BarsController>)> n
Completed 500 Internal Server Error in 2685ms (ActiveRecord: 0.0ms)
RuntimeError - No frames collected.:
pry-byebug (3.2.0) lib/byebug/processors/pry_processor.rb:122:in `perform_next'
pry-byebug (3.2.0) lib/byebug/processors/pry_processor.rb:60:in `perform'
pry-byebug (3.2.0) lib/byebug/processors/pry_processor.rb:49:in `run'
pry-byebug (3.2.0) lib/byebug/processors/pry_processor.rb:111:in `resume_pry'
pry-byebug (3.2.0) lib/byebug/processors/pry_processor.rb:69:in `at_line'
byebug (5.0.0) lib/byebug/context.rb:90:in `at_line'
app/controllers/scholarships_controller.rb:31:in `edit'
actionpack (4.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.1) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.1) lib/active_support/callbacks.rb:117:in `call'
# omitting the next ~40 lines in the Rails stack...
第二节看起来和第一节一样——此时执行返回到服务器。
这是我的 Gemfile:
source 'https://rubygems.org'
ruby '2.2.0'
gem 'rails', '4.2.1'
gem 'pg', '~> 0.18.2'
gem 'haml-rails', '~> 0.9.0'
gem 'sass-rails', '~> 5.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'will_paginate', '~> 3.0.7'
gem 'will_paginate-bootstrap'
gem "nilify_blanks"
gem 'filterrific', '~> 2.0.5'
gem 'chardinjs-rails'
# Install bootstrap and associated gems
gem 'bootstrap-sass', '~> 3.3.4.1'
gem 'autoprefixer-rails', '~> 5.2.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
group :production do
gem 'rails_12factor', '~> 0.0.3'
end
group :assets do
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
end
group :development do
gem 'better_errors', '~> 2.1.1'
gem 'annotate', '~> 2.6.10'
end
group :development, :test do
gem 'pry-rails'
gem 'pry-stack_explorer'
gem 'pry-byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
gem 'spring-commands-rspec', '~> 1.0.4'
gem 'rspec-rails', '~> 3.2.3'
gem 'guard-rspec', '~> 4.6.0'
gem 'sqlite3'
gem 'factory_girl_rails', '~> 4.5.0', require: false
end
group :test do
gem 'database_cleaner', '~> 1.4.1'
gem 'faker', '~> 1.4.3'
gem 'capybara', '~> 2.4.4'
gem 'launchy', '~> 2.4.3'
gem 'shoulda', '~> 3.5.0'
end
我也尝试过pry-stack_explorer
pry-byebug
注释掉的和宝石......没有区别。
最后,我的 .pryrc 文件:
# ~/.pryrc
if defined?(PryByebug)
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 'f', 'finish'
end
# Hit Enter to repeat last command
Pry::Commands.command /^$/, "repeat last command" do
_pry_.run_command Pry.history.to_a.last
end