Rails应用程序向自定义“获取”路线提交“发布”请求

时间:2013-09-09 19:53:44

标签: ruby-on-rails routes

我的应用中有此按钮,位于views / deals / mgmt.htm.erb文件中:

<%= button_to "Deals", deals_mgmt_path, class: "btn btn-default" %>

以下是我的路线文件中指定的“交易”路线:

resources :deals
get "deals/mgmt"

当我运行'rake routes'时,这是我指定的路线:

deals_mgmt GET    /deals/mgmt(.:format)                    deals#mgmt

当我点击按钮时,我收到此路由错误:

No route matches [POST] "/deals/mgmt"

为什么我的rails尝试在此处提交帖子请求?我很困惑。提前谢谢!

2 个答案:

答案 0 :(得分:2)

帮助器button_to创建一个表单,表单向服务器提交POST个请求。
检查页面,您将看到表格 对于使用link_to的请求,您应该使用GET

答案 1 :(得分:0)

You can use this: 

<%= button_to 'deals', deals_management_path, {:method => get} %>

Else
it's better to Go with link_to as by default it send get request to Server.

<%= link_to 'deals', deals_management_path %>