2011-09-29 73 views
0

link_to的API中,您可以看到,您可以通過一個論據:method => :post。在Rails 2中,它使用POST動詞創建一個表單,並在單擊鏈接時提交表單。但是,這可以用來將隱藏的字段傳遞給表單而不顯示在URL中嗎?我的意思是建立這樣的事情:我們可以在`link_to`標籤中使用`:method =>:post`參數來隱藏URL中的參數嗎?

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

那是後話不使flag參數出現在URL中。我嘗試使用link_to:method => :post,但我不知道如何將參數flag傳遞給link_to。當我嘗試這個link_to "View", {:controller => :test, :action => :view, :flag => 1}, :method => :post時,它正在創建一個表單,但url仍然是/test/view?flag=1

回答

1

我相信所有傳遞給link_to的參數都將成爲URL的一部分。解決方案是要麼手工創建一個表單,要麼編寫自己的幫手來實現你想要的。