在 Rails 中快速渲染所有传递的参数

发布于 2024-10-06 08:56:01 字数 145 浏览 6 评论 0原文

我有一个表单,可以填充各种值,然后在用户提交时将这些值发布到页面。现在,我希望查看 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不必你懂 2024-10-13 08:56:01

另一种方法是利用辅助函数进行调试,如 http://guides.rubyonrails.org/ 中所述debug_rails_applications.html

如前所述,该技术是使用 params.to_yaml。

或者,在您的 application.html.erb 文件中,将代码放在

<%= debug(params) if Rails.env.development? %>

<%= yield %> 调用之后,

这将在视图中显示参数,

--- !map:ActiveSupport::HashWithIndifferentAccess 
action: edit
controller: contracts
id: "8"

例如一个很好的功能是,信息仅在开发模式环境中输出,根据执行的检查以确定哪个 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 code

<%= debug(params) if Rails.env.development? %>

after the <%= yield %> call

This will display in the view the params, for example

--- !map:ActiveSupport::HashWithIndifferentAccess 
action: edit
controller: contracts
id: "8"

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.

被你宠の有点坏 2024-10-13 08:56:01

在您的视图中尝试 <%= params.to_yaml %>

Try <%= params.to_yaml %> in your view

铁轨上的流浪者 2024-10-13 08:56:01

尝试在您发布的视图中使用此视图

    <%= params[:name_of_posted_param].each {|param|
    params //do something with the param here
} %>

更好的方法是在助手中执行此操作并在视图中传递返回变量。

-R

Try using in this view in the view you are posting

    <%= params[:name_of_posted_param].each {|param|
    params //do something with the param here
} %>

A better way would be to do this in the helper and pass the returning variable in the view.

-R

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文