manually invoking routing?

Hey folks. I have a rails controller which is filtering search results
for access control. The search results are typically URLs into the rest
of the rails app. I'm finding it would simplify the grotty code which is
accumulating if I could manually invoke the router. That is to say, if I
could send something a URI path string and get back the hash of
controller, action, and params that would be invoked if this had been a
real request. Is this possible?

- donald

I'm not sure how to do it, but this may be of some help:

http://weblog.jamisbuck.org/2006/10/4/under-the-hood-route-recognition-in-rails

I'm not sure how to do it, but this may be of some help:

http://weblog.jamisbuck.org/2006/10/4/under-the-hood-route-rec

ognition-in-rails

Thanks, that does illuminate much. This snippet works in the console:

result_params =
ActionController::Routing::Routes.recognize_path(uri.path)

but it throws a NameError when I try it in a controller action:

uninitialized constant
ActionWebService::Dispatcher::ActionController::Routing

I've tried a few different flavors of the fully qualified class name but
haven't found one that works yet. Any suggestions?

- donald

Thanks, that does illuminate much. This snippet works in the console:

result_params =
ActionController::Routing::Routes.recognize_path(uri.path)

but it throws a NameError when I try it in a controller action:

uninitialized constant
ActionWebService::Dispatcher::ActionController::Routing

I've tried a few different flavors of the fully qualified
class name but haven't found one that works yet. Any suggestions?

Criminy, I got it to work by the following mechanism:

  class << self
    def recognize_path(path)
      ActionController::Routing::Routes.recognize_path(path)
    end
  end

  def index
    ...
    result_params = self.class.recognize_path(uri.path)
    ...
  end

Any notion why this works when I wrap it up in a metaclass method??

- donald