开发者

Is it possible to add a value to a submit button that gets passed in the params?

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

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 wh开发者_如何学Pythonich one was pressed in the controller and render the view accordingly?

Is this the best way to do this?


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

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

if params[:submit] == "preview"


You can add a button click event with javascript that will fill a hidden value and pass it along with the rest of your parameters. If using jQuery:

$("#post_button").click(function() {
   $("#form_action").val("post");
});

$("#preview_button").click(function() {
   $("#form_action").val("preview");
});

You'd then access the action in your controller using params['form_action']

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜