# "Recognizing" a controller and action from an URL?

**URL:** <https://www.ruby-forum.com/t/recognizing-a-controller-and-action-from-an-url/110282>\
**Category:** Rails\
**Created:** [July 24, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/recognizing-a-controller-and-action-from-an-url/110282 "2007-07-24T22:20:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![darth\_ivan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@darth\_ivan](https://www.ruby-forum.com/u/darth_ivan)\
**Post date:** [July 24, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/recognizing-a-controller-and-action-from-an-url/110282/1 "2007-07-24T22:20:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![darth\_ivan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@darth\_ivan](https://www.ruby-forum.com/u/darth_ivan)\
**Post date:** [July 24, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/recognizing-a-controller-and-action-from-an-url/110282/2 "2007-07-24T22:32:22Z")

</div>

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.
