[英]Rails 2.3.12: Limiting routes to specific HTTP verbs
I have a status controller for reporting how my application is functioning. 我有一个状态控制器,用于报告我的应用程序如何运行。 It has two basic actions:
它有两个基本动作:
The paths are status
and status/ping
respectively. 路径分别是
status
和status/ping
。
I want to restrict these to only GET
for status
and only POST
for status/ping
. 我想将它们限制为仅
GET
表示status
而仅 POST
表示status/ping
。 The current route structure looks like this: 当前的路由结构如下所示:
map.connect('status', :controller => 'status', :action => 'index')
map.connect('status/ping', :controller => 'status', :action => 'ping')
I've tried various combinations of :via
and :only
with no success. 我尝试了
:via
和:only
各种组合,但均未成功。
How can I impose verb restrictions on these paths? 如何在这些路径上施加动词限制?
Thanks! 谢谢!
The :only
option is for the Restful routes. :only
选项用于Restful路由。 According to the 2.3.8 docs , what you're looking for is the following. 根据2.3.8 docs ,您正在寻找以下内容。
map.connect('status', :controller => 'status', :action => 'index', :conditions => { :method => :get })
map.connect('status/ping', :controller => 'status', :action => 'ping', :conditions => { :method => :post })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.