form_for being submitting by 2 links, how to I tell which was used when I am back in the controller?

断了今生、忘了曾经 提交于 2019-12-02 17:05:37

问题


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...

Any idea ? I have tried to embed some javascript, etc. but I could not figure it out.

Thanks,

Alex


回答1:


= 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()"

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.



来源:https://stackoverflow.com/questions/4774818/form-for-being-submitting-by-2-links-how-to-i-tell-which-was-used-when-i-am-bac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!