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
。