我有一个链接,我需要提交一个发布请求。通常,我会使用jQuery并阻止链接的默认行为,然后将表单提交到目标。这看起来像Rails应该能够帮助我。果然,link_to
方法用于指定HTTP POST方法的选择:使用Rails的link_to发布的链接
link_to "Profile", 'http://example.com/profile', method: :post
这样的作品,但我需要添加2个参数了。我想:
link_to "Profile", 'http://example.com/profile', method: post, param1: 'value1', param2: 'value2'
这只是增加了这些参数的<a>
HTML元素,但点击该链接时,没有提交这些:
<a rel="nofollow" param1="value1" param2="value2" data-method="post" href="http://example.com/profile">Profile</a>
有没有办法做一个带参数的POST请求使用link_to
或其他Rails方法?我正在使用Rails 3.2.9。
不认为你可以做到这一点。可能最好在你的控制器使用net/http或HTTParty来完成它? –
无法在我的控制器中执行此操作,需要将用户引导至其他站点。看起来你是对的,但没有内置的链接机制来为我做这件事。 –