Ruby on rails 普赖尔:给我看看那堆东西
当我在代码中遇到断点时,使用Pry-in-Rails 捆绑,撬动 我想知道我是如何来到这里的,谁给我打电话,谁给他们打电话,等等。但奇怪的是,我看不到那个命令。有人知道吗 有哪个节目是Pry会话的回溯 还有。这是最新异常的回溯。添加更多问号以查看更多回溯,或添加感叹号以查看所有回溯 键入pry查看所有其他命令:)使用插件,它允许您上下移动调用堆栈(使用Ruby on rails 普赖尔:给我看看那堆东西,ruby-on-rails,pry,Ruby On Rails,Pry,当我在代码中遇到断点时,使用Pry-in-Rails 捆绑,撬动 我想知道我是如何来到这里的,谁给我打电话,谁给他们打电话,等等。但奇怪的是,我看不到那个命令。有人知道吗 有哪个节目是Pry会话的回溯 还有。这是最新异常的回溯。添加更多问号以查看更多回溯,或添加感叹号以查看所有回溯 键入pry查看所有其他命令:)使用插件,它允许您上下移动调用堆栈(使用向上和向下),显示调用堆栈(使用显示堆栈),等等: 请看这里: Frame number: 0/64 From: /Users/johnmair
向上和向下),显示调用堆栈(使用显示堆栈
),等等:
请看这里:
Frame number: 0/64
From: /Users/johnmair/ruby/rails_projects/personal_site/app/controllers/posts_controller.rb @ line 7 PostsController#index:
5: def index
6: @posts = Post.all
=> 7: binding.pry
8: end
[1] pry(#<PostsController>)> show-stack
Showing all accessible frames in stack (65 in total):
--
=> #0 index <PostsController#index()>
#1 [method] send_action <ActionController::ImplicitRender#send_action(method, *args)>
#2 [method] process_action <AbstractController::Base#process_action(method_name, *args)>
#3 [method] process_action <ActionController::Rendering#process_action(*arg1)>
<... clipped ...>
[2] pry(#<PostsController>)> up
Frame number: 1/64
Frame type: method
From: /Users/johnmair/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb @ line 4 ActionController::ImplicitRender#send_action:
3: def send_action(method, *args)
=> 4: ret = super
5: default_render unless response_body
6: ret
7: end
[3] pry(#<PostsController>)>
帧编号:0/64
From:/Users/johnmair/ruby/rails_projects/personal_site/app/controllers/posts_controller.rb@line 7 PostsController#index:
5:def索引
6:@posts=Post.all
=>7:binding.pry
8:完
[1] 撬动(#)>显示堆栈
显示堆栈中所有可访问的帧(共65个):
--
=>#0索引
#1[方法]发送\u操作
#2[方法]过程\行动
#3[方法]过程\行动
[2] 撬起
帧号:1/64
框架类型:方法
From:/Users/johnmair/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-3.2.8/lib/action\u controller/metal/implicit\u render.rb@line 4 ActionController::ImplicitRender\35; send\u action:
3:def发送操作(方法*args)
=>4:ret=super
5:默认渲染,除非响应体
6:ret
7:完
[3] 撬动(#)>
若要在没有任何pry插件的情况下完成此操作(我在pry-stack_explorer上遇到了问题),请查看
实际上,我在寻找我的项目名称,以过滤掉所有不相关的rails堆栈项。例如,如果我的项目名称是archie
,我会使用:
caller.select {|line| line.include? "archie" }
这给了我要找的堆栈跟踪
较短的方法是:
caller.select {|x| x["archie"] }
这同样有效。您可以使用gem库中已经定义的调用方方法。该方法的返回值将是一个数组。因此,您可以应用事件数组方法在这一系列行中进行搜索
下面也有助于强大的跟踪。
延伸保罗·奥利弗的答案
如果您有一个要永久排除的短语列表,可以使用Pry中的自定义命令功能来实现
在~/.pryrc
中:
Pry::Commands.block_command "callerf", "Filter the caller backtrace" do
output = caller.reject! { |line| line["minitest"] || line["pry"] }
puts "\e[31m#{output.join("\n")}\e[0m"
end
调用callerf
将导致过滤的调用方
输出。#{output}
周围的奇怪标志上色以复制调用方的原始外观。我把颜色从我的手上拿了下来
或者,如果您不想自定义命令,请使用Ctrl+R
搜索命令历史记录。pry backtrace
可以,但是pry-stack\u explorer
插件功能更强大(尽管它是另一个gem,一个插件),但事实是有时您不使用所有这些功能:)这非常棒。我很恼火,因为它包含了pry调用堆栈,我只想从我的应用程序中得到什么+1.完美的我在tmux中添加了一个键组合来输入它(bind'B'send keys'.^M'),使用了一个“reject”来代替它,这样它就更通用了:caller.reject{x | x[“vendor/bundle”]| x[“/.rbenv/versions/”])
True to form for the Ruby community,唯一有用的答案是建议你去安装一些插件。这个答案值得很多人投票。是的,你可以在pry上面安装更多的东西。但是您也可以使用ruby现有的语言特性来获得几乎相同的结果(当然,这足以回答OP的问题!)这个答案应该是正确的,因为它不需要额外的插件!它在主文件夹~/.pryrc
中。如果没有,就创建它<代码>~/
在Unix系统上始终表示主文件夹。