简体   繁体   English

Rails 2.3.12:将路由限制为特定的HTTP动词

[英]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: 它有两个基本动作:

  1. How do things look right now? 现在情况如何?
  2. Poke all the pieces to update their status, and then process as #1. 戳所有碎片以更新其状态,然后处理为#1。

The paths are status and status/ping respectively. 路径分别是statusstatus/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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM