Button_to 使用 POST Link_to 使用 GET,为什么?回报率 [英] Button_to uses POST Link_to uses GET, why? ROR

查看:62
本文介绍了Button_to 使用 POST Link_to 使用 GET,为什么?回报率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 link_to 时遇到了错误问题.为什么我的链接使用 GET 方法而我的 button_to 使用 POST 方法,在我在 link_to 参数中指定我的方法"=>发布"之后?

I've ran into a ror problem using the link_to. Why does my link to use the GET method and my button_to use the POST method, after I specified my "method"=>"post" within the link_to parameters?

查看:

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

控制器方法:

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

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

Terminal Output (Button/Link, respectively):

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 选项位于不同的哈希中:

I think your html options have to be in a separate hash from your url options:

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

我四处寻找一个合适的例子,但没有运气.对于我的代码,我基本上已经放弃,只使用新样式:

I looked all over for a proper example, with no luck. For my code, I've mostly given up and just use the new style:

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

这篇关于Button_to 使用 POST Link_to 使用 GET,为什么?回报率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆