Rails 2.3.12:分别路由"GET /foo"、"PUT /foo"和'<any> /foo/bar'



我有一个Rails 2.3.12应用程序,它是另一个应用程序的前端。调用另一个应用程序foo;所有发送到我的应用程序的uri都将以/foo开头。我的Rails应用程序需要处理这些情况:

  1. GET /foo—我的应用程序直接处理(返回支持的列表)
  2. <anything-else> /foo—返回401 (即。GET是唯一支持的HTTP动词)
  3. <anything> /foo/<anything>——由我的应用程序处理,传递给foo应用程序。
不幸的是,到目前为止,我所有的尝试都导致所有都被情况1&2或情况3所填充。以下是我目前在routes.rb中的内容:
     map.root(:controller       => 'application',
              :action           => 'render_401_unauthorised')
  map.connect('fooapp/*fooapp_ep_path',
              :controller       => 'foo',
              :action           => 'parsepath')
  map.connect('fooapp',
              :controller       => 'other_controller',
              :action           => 'index',
              :conditions       => { :method => :get })
  map.connect('fooapp',
              :controller       => 'application',
              :action           => 'render_401_unauthorised')

我想我的问题会消失,如果我能确保第一个map.connect只有匹配,如果*fooap_ep_path不是空的——即。,匹配正则表达式%r!/foo/.+!

这能做到吗?

谢谢!

已更新如果有任何方法可以指定glob路径必须为[非]空,则可能会提供必要的粘合

我沿着

的行使用#with_options来计算。
map.with_options({}) do |ap,*args|
  ap.name1('fooapp',
           :controller    => 'can_do',
           :action        => 'index',
           :conditions    => { :method => :get }
          )
  ap.name2('fooapp',
           :controller    => 'can_do',
           :action        => 'render_403_forbidden'
          )
  ap.name3('fooapp/*fooapp_path',
           :controller    => 'other',
           :action        => 'do_it'
          )
end

最新更新