我有一个Rails 2.3.12应用程序,它是另一个应用程序的前端。调用另一个应用程序foo
;所有发送到我的应用程序的uri都将以/foo
开头。我的Rails应用程序需要处理这些情况:
-
GET /foo
—我的应用程序直接处理(返回支持的列表) -
<anything-else> /foo
—返回401 (即。,GET
是唯一支持的HTTP动词) -
<anything> /foo/<anything>
——由我的应用程序处理,传递给foo
应用程序。
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