在 Rails 中快速渲染所有传递的参数
我有一个表单,可以填充各种值,然后在用户提交时将这些值发布到页面。现在,我希望查看 params[] 包含什么(通过将其显示在我发布的页面上),只是为了稍微玩一下我的表单定义。我寻找一种简单的方法来渲染参数,但还没有找到解决方案。有什么有用的建议吗?
提前致谢
I have a form that populates various values, then posts those values to a page when the user submits. Now, I wish to see what params[] contains (by displaying it on the page I post to) just to fool around with my form definitions a little bit. I looked for an easy way to render params, but haven't quite found the solution. Any helpful suggestions SO?
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一种方法是利用辅助函数进行调试,如 http://guides.rubyonrails.org/ 中所述debug_rails_applications.html
如前所述,该技术是使用 params.to_yaml。
或者,在您的
application.html.erb
文件中,将代码放在<%= yield %>
调用之后,这将在视图中显示参数,
例如一个很好的功能是,信息仅在开发模式环境中输出,根据执行的检查以确定哪个 Rails 环境正在运行。
Another way is to make use of the helper functions for debugging as described in http://guides.rubyonrails.org/debugging_rails_applications.html
The technique, as previously described is to use params.to_yaml.
Alternatively, in your
application.html.erb
file put the codeafter the
<%= yield %>
callThis will display in the view the params, for example
The nice feature is that the information is only output in the Development mode environment, as per the check that is executed to determine which Rails environment is running.
在您的视图中尝试
<%= params.to_yaml %>
Try
<%= params.to_yaml %>
in your view尝试在您发布的视图中使用此视图
更好的方法是在助手中执行此操作并在视图中传递返回变量。
-R
Try using in this view in the view you are posting
A better way would be to do this in the helper and pass the returning variable in the view.
-R