# "reverse" routes - getting a controller and action from a UR

**URL:** <https://www.ruby-forum.com/t/reverse-routes-getting-a-controller-and-action-from-a-ur/89496>\
**Category:** Rails\
**Created:** [March 20, 2007, 9:14pm UTC](https://www.ruby-forum.com/t/reverse-routes-getting-a-controller-and-action-from-a-ur/89496 "2007-03-20T21:14:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 20, 2007, 9:14pm UTC](https://www.ruby-forum.com/t/reverse-routes-getting-a-controller-and-action-from-a-ur/89496/1 "2007-03-20T21:14:40Z")

</div>

I’m using redirect\_to :back in my app in one place. In a couple cases  
I need to see if the http referrer is a certain controller/action  
pair, and do something differently based on that. Is there some way  
to get the url options from a url string?

Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 20, 2007, 9:56pm UTC](https://www.ruby-forum.com/t/reverse-routes-getting-a-controller-and-action-from-a-ur/89496/2 "2007-03-20T21:56:47Z")

</div>

Pat,

You want to take a look at  
ActionController::Routing::Routes.recognize\_path

I don’t know if you have the Pragmatic Agile book, 2nd edition. If  
so, check out page 398 (chapter 20, “Action Controller: Routing and  
URLs”). If not, check out this example from my console:

> > ActionController::Routing::Routes.recognize\_path “/users”  
> > =\> {:controller=\>“users”, :action=\>“index”}
> 
> > ActionController::Routing::Routes.recognize\_path “/users/5”  
> > =\> {:controller=\>“users”, :action=\>“5”}
> 
> > ActionController::Routing::Routes.recognize\_path “/users/5”, :method =\> :get  
> > =\> {:controller=\>“users”, :action=\>“show”, :id=\>“5”}
> 
> > ActionController::Routing::Routes.recognize\_path “/users/5”, :method =\> :put  
> > =\> {:controller=\>“users”, :action=\>“update”, :id=\>“5”}
> 
> > ActionController::Routing::Routes.recognize\_path “/users”, :method =\> :post  
> > =\> {:controller=\>“users”, :action=\>“create”}

–  
-yossef
