Button_to使用POST Link_to使用GET,为什么? ROR

我使用link_to遇到了一个问题。 在link_to参数中指定我的“method”=>“post”后,为什么我的链接使用GET方法而我的button_to使用POST方法?

视图:

 'getquote' %>  'inventories', :action => 'getquote', :method => :post } %> 

控制器方法:

 def getquote @cart = find_cart respond_to do |format| format.pdf end end 

终端输出(分别为按钮/链接):

 Processing InventoriesController#getquote (for 127.0.0.1 at 2010-01-30 01:38:02) [POST] Parameters: {"action"=>"getquote", "authenticity_token"=>"D2cwnHyTHgomdUM3wXBBXlOe4NQLmv1Srn0paLbExpQ=", "controller"=>"inventories"} Processing InventoriesController#show (for 127.0.0.1 at 2010-01-30 01:39:07) [GET] Parameters: {"method"=>"post", "action"=>"show", "id"=>"getquote", "controller"=>"inventories"} 

我认为你的html选项必须与你的url选项分开一个哈希:

 <%= link_to 'pdf', {:controller => 'inventories', :action => 'getquote'}, {:method => :post } %> 

我好好看了一遍,没有运气。 对于我的代码,我大多放弃了,只使用新的风格:

 <%= link_to 'Delete', custom_event, :confirm => 'Are you sure?', :method => :delete %> 

可能对正在访问的人有用:)

默认情况下,button_to仅执行POST操作。

做一个GET的语法如下:

 <%= button_to 'pdf', { :action => 'getquote'}, :method => :get %> 

一种可能是您禁用了Javascript,在这种情况下它将回退到GET。