form_for通过2个链接提交,当我回到控制器中时,如何告诉我使用了哪个? [英] form_for being submitting by 2 links, how to I tell which was used when I am back in the controller?
问题描述
我将表单放在一起,但出于设计原因,表单必须通过链接提交。
我发现了如何执行该操作:
I putting a form together, but for design reason the form must be submitted by a link. I found out how to perform that:
= link_to_function "Next >>", "$(this).up('form').submit()"
这样做,我可以创建许多与此相关的问题没有问题。但是我不知道如何区分使用哪个链接将我带回控制器?
我需要根据链接略有不同...
This will do, and I can create many link with this no problem. However I don't know how to distinguish which link was used to bring me back to the controller ? I need to perform slightly different depending on the link...
有什么想法吗?我试图嵌入一些javascript等,但我无法弄明白。
Any idea ? I have tried to embed some javascript, etc. but I could not figure it out.
谢谢,
Alex
推荐答案
= link_to_function "Next >>", "$('#hidden_field').value = 1;$(this).up('form').submit()"
= link_to_function "Next 2 >>", "$('#hidden_field').value = 2;$(this).up('form').submit()"
假设你'重新使用jquery,根据单击的链接将隐藏字段设置为不同的值。毕竟link_to_function的第二个参数只是javascript。
Assuming you're using jquery, set a hidden field to different values depending on which link was clicked. The 2nd parameter to link_to_function is merely javascript, after all.
这篇关于form_for通过2个链接提交,当我回到控制器中时,如何告诉我使用了哪个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!