是否可以向在参数中传递的提交按钮添加值? [英] Is it possible to add a value to a submit button that gets passed in the params?

查看:73
本文介绍了是否可以向在参数中传递的提交按钮添加值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的应用添加预览"按钮/页面.

I'm trying to add a "preview" button/page to my app.

是否可以为在params哈希中传递的发布"和预览"提交按钮添加不同的值,以便我可以检查在控制器中按下了哪个按钮并相应地渲染视图?

Is there a way to add a different value to both my "post" and "preview" submit buttons that get passed in the params hash so that I can check which one was pressed in the controller and render the view accordingly?

这是最好的方法吗?

推荐答案

params哈希的键只是元素的name值.

The keys of the params hash are just the name value of an element.

如果您有两个名为提交"的按钮,其中一个带有value="post"value="preview",那么您可以执行以下操作:

If you had two buttons named "submit", one with value="post" and value="preview", then you could do something like:

if params[:submit] == "preview"

这篇关于是否可以向在参数中传递的提交按钮添加值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆