当我在代码binding.pry中遇到断点时,在Rails中使用撬动
我想知道我是如何来到这里的,是谁给我打电话的,是谁给他们打电话的,等等。但奇怪的是,我看不到这个命令。有人知道吗?
发布于 2013-03-09 10:09:49
使用pry-stack_explorer插件,它允许您在调用堆栈中上下移动(使用up和down),显示调用堆栈(使用show-stack),等等:
请看这里:
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>)> 发布于 2014-02-07 13:49:04
要在没有任何撬动插件的情况下做到这一点(我在使用pry -stack_explorer时遇到了问题),只需看看caller。
实际上,我会查找我的项目名来过滤掉所有不相关的rails堆栈项。例如,如果我的项目名称是archie,我会使用:
caller.select {|line| line.include? "archie" }这给了我正在寻找的堆栈跟踪。
一种更短的方法是:
caller.select {|x| x["archie"] }这也很好用。
发布于 2013-03-09 05:25:52
https://stackoverflow.com/questions/15303103
复制相似问题