开发者

can we use `:method => :post` parameter in `link_to` tag to hide parameter from URL?

开发者 https://www.devze.com 2023-04-09 00:06 出处:网络
In the API for link_to, you can see, you can pass an arguement, :method => :post. In Rails 2, it creates a form with POST verb and submits the form on clicking the link. But, can this be used to pa

In the API for link_to, you can see, you can pass an arguement, :method => :post. In Rails 2, it creates a form with POST verb and submits the form on clicking the link. But, can this be used to pass hidden fields to the form without appearing in URL? I mean building something like this:

<form name="test_form" action="/test/view" method=开发者_如何转开发"post">
  <input type="hidden" id="flag" name="flag" value=3 />
</form>
<a href="#" onclick="document.form.test_form.submit()">View</a>

that is something which does not make the flag parameter to appear in the url. I tried using link_to with :method => :post, but I am not sure how to pass the parameter flag to the link_to. When I tried this link_to "View", {:controller => :test, :action => :view, :flag => 1}, :method => :post, it is creating a form, but the url is still /test/view?flag=1.


I believe all params passed to link_to will become a part of the URL. The solution is to either create a form by hand, or write your own helper to achieve exactly what you want.

0

精彩评论

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