相同的Rails 4路由用于GET和POST请求 [英] Same Rails 4 routes for GET and POST requests

查看:151
本文介绍了相同的Rails 4路由用于GET和POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Rails 3 Match中,它同时指向 GET POST 以及其他类型的请求的动作。

In Rails 3 Match used to point to an action for both "GET" and "POST" and other type of requests.

match "user/account" => user#account

现在,这将指向GET和POST请求的用户控制器的帐户操作。
Rails 4 中的比赛已被弃用一样,我们可以在Rails 4中为 GET POST 创建相同的路线吗? / p>

Now this will point to account action of user's controller for both GET and POST requests. As in Rails 4 "match" has been deprecated, can we create same route for GET and POST in Rails 4?

推荐答案

match 文档中,您可以使用 match ,只要您通过

match "user/account" => "user#account", as: :user_account, via: [:get, :post]

编辑:添加了 as:参数,以便可以通过url帮助器对其进行访问。 user_account_path user_account_url

Added a as: parameter so that it will be accessible via a url helper. user_account_path or user_account_url in this case.

这篇关于相同的Rails 4路由用于GET和POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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