# Manually invoking routing?

**URL:** <https://www.ruby-forum.com/t/manually-invoking-routing/116259>\
**Category:** Rails\
**Created:** [October 3, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/manually-invoking-routing/116259 "2007-10-03T22:50:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [October 3, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/manually-invoking-routing/116259/1 "2007-10-03T22:50:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [October 3, 2007, 11:03pm UTC](https://www.ruby-forum.com/t/manually-invoking-routing/116259/2 "2007-10-03T23:03:06Z")

</div>

On 10/3/07, Ball, Donald A Jr (Library) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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?

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](http://weblog.jamisbuck.org/2006/10/4/under-the-hood-route-recognition-in-rails)

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [October 4, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/manually-invoking-routing/116259/3 "2007-10-04T20:51:23Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [October 4, 2007, 8:37pm UTC](https://www.ruby-forum.com/t/manually-invoking-routing/116259/4 "2007-10-04T20:37:55Z")

</div>

> 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](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
