【问题标题】:How to I access the request object when debugging with pry?使用 pry 调试时如何访问请求对象?
【发布时间】:2012-12-30 17:27:32
【问题描述】:

我试图弄清楚 spree_easy 联系人 gem 中的 admin/topics 控制器中发生了什么。控制器中有这段代码:

new_action.response do |wants|
  wants.html {render :action => :new, :layout => !request.xhr?}
end

我想看看request.xhr? 解析到什么。我如何使用 pry 调试来访问它?

【问题讨论】:

  • 将 binding.pry 放在 do 块的末尾有什么问题? ...!request.xhr?} binding.pry end
  • .xhr? 检查是否存在header[X-Requested-With]

标签: ruby-on-rails ruby debugging pry


【解决方案1】:

只要放在最上面:

binding.pry
new_action.response do |wants|
  wants.html {render :action => :new, :layout => !request.xhr?}
end

request 在控制器中的任何地方都是相同的,所以只要调用了binding.pry 就没有关系。另外,你可以看到implementation of xhr? on GitHub

【讨论】:

  • 好吧,假设我正确设置了 binding.pry 调用并正确进入调试器会话,我究竟应该在 pry 控制台中输入什么来访问 request.xhr 的值?
  • @RebekahWaterbury 你输入request.xhr?...
  • 嗯,这回答了你的问题吗?别忘了upvote/accept answers to your questions:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-10
  • 1970-01-01
相关资源
最近更新 更多