开发者

Rails 2.3.12: Routing 'GET /foo', 'PUT /foo', and '<any> /foo/bar' separately

开发者 https://www.devze.com 2023-04-03 05:24 出处:网络
I have a Rails 2.3.12 app that is fronting for another application.Call the other application foo; all URIs sent to my app will begin with /foo.My Rails app needs to handle these cases:

I have a Rails 2.3.12 app that is fronting for another application. Call the other application foo; all URIs sent to my app will begin with /foo. My Rails app needs to handle these cases:

  1. GET /foo -- my app handles directly (returns a list of what's supported)
  2. <anything-else> /foo -- returns a 401 (i.e., GET is the only supported HTTP verb)
  3. <anything> /foo/<anything> -- gets handled by my app to be passed to the foo app.

Unfortunately, all of my attempts so far have resulted in every开发者_开发百科thing being fielded by either cases 1&2 or by case 3. Here's what I have in my routes.rb at the moment:

     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')

I think my problem would go away if I could ensure that the first map.connect would only match if *fooap_ep_path isn't empty -- i.e., matches the regex %r!/foo/.+!

Can this be done?

Thanks!

Updated If there is any way to specify that a glob path must be [non]empty, that would probably provide the necessary glue.


I worked this out using #with_options along the lines of

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
0

精彩评论

暂无评论...
验证码 换一张
取 消