[英]binding.pry in Rails View: NameError: undefined local variable or method
我将Rails 4与gems byebug,pry-rails,pry-byebug和pry-stack_explorer一起使用。
当我替换视图文件时:
<td class="subtotal"><%= order.display_item_total %></td>
与
<td class="subtotal"><%= binding.pry %></td>
并在运行rails服务器进程的控制台内键入,并在撬断点处停止执行:
order.inspect
我收到错误消息:
NameError: undefined local variable or method `order' for #<ActionView::OutputBuffer:0x007fdf13d99bb8>
当我用order.inspect替换binding.pry时,我在浏览器中获得了order的对象信息。
我希望我应该能够在控制台的撬会话中获得对象顺序。 我究竟做错了什么?
编辑:在控制台输出的开头:
From: /Users/standardnerd/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/string/output_safety.rb @ line 166 ActiveSu
pport::SafeBuffer#safe_concat:
165: def safe_concat(value)
=> 166: raise SafeConcatError unless html_safe?
167: original_concat(value)
168: end
这会影响变量的范围吗?
线
<td class="subtotal"><%= binding.pry %></td>
试图输出的响应binding.pry
的观点,我认为这是一个触发您的SafeConcatError
,我怀疑你没有访问正确的绑定。
更好的办法是...
<% binding.pry %>
<td class="subtotal"><%= order.display_item_total %></td>
...因此在尝试渲染总计之前立即进行pry
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.