"Recognizing" a controller and action from an URL?


#1

Hi,

I’m trying to find something in ActionController::Routing that can help
me find out which controller and action are responsible for a certain
URL.

So far it seems something like this might be an answer:

request, response = ActionController::CgiRequest.new(cgi,
session_options),
ActionController::CgiResponse.new(cgi)

controller = ActionController::Routing::Routes.recognize(request)

But how would I build the cgi and session_options parameters?

Is there a simpler way?

Thanks.

  • Ivan V.

#2

Ivan V. wrote:

Hi,

I’m trying to find something in ActionController::Routing that can help
me find out which controller and action are responsible for a certain
URL.

So far it seems something like this might be an answer:

request, response = ActionController::CgiRequest.new(cgi,
session_options),
ActionController::CgiResponse.new(cgi)

controller = ActionController::Routing::Routes.recognize(request)

But how would I build the cgi and session_options parameters?

Is there a simpler way?

Thanks.

  • Ivan V.

Yeah, much simpler:

ActionController::Routing::Routes.recognize_path(path)

That returns a hash with the controller and action names.

This will do wonders for my authentication system!

I hope this is useful to somebody else besides me.

  • Ivan V.

PS: NetBeans 6 debugging rocks. Try it if you haven’t already.