方法
- D
包含的模块
实例公共方法
debug(object) 链接
返回 object 的 YAML 表示形式,并用 <pre> 和 </pre> 包裹。如果对象无法通过 to_yaml 转换为 YAML,则会调用 inspect。在渲染时检查对象非常有用。
@user = User.new({ username: 'testing', password: 'xyz', age: 42})
debug(@user)
# =>
<pre class='debug_dump'>--- !ruby/object:User
attributes:
updated_at:
username: testing
age: 42
password: xyz
created_at:
</pre>
来源: 显示 | 在 GitHub 上
# File actionview/lib/action_view/helpers/debug_helper.rb, line 28 def debug(object) Marshal.dump(object) object = ERB::Util.html_escape(object.to_yaml) content_tag(:pre, object, class: "debug_dump") rescue # errors from Marshal or YAML # Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback content_tag(:code, object.inspect, class: "debug_dump") end