2011-09-06 68 views
1

我有一个面向另一个应用程序的Rails 2.3.12应用程序。致电其他应用foo;发送到我的应用程序的所有URI将以/foo开头。我的Rails应用程序需要处理这些案件:Rails 2.3.12:分别路由'GET/foo','PUT/foo'和'<any>/foo/bar'

  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/.+!

可以这样做吗?

谢谢!

更新如果有任何的方式来指定一个水珠路径必须将[无]空,这可能会提供必要的胶水。

回答

0

我工作了这一点,使用#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 
线