# Rerouting between controller's actions \*WITHOUT REDIRECT\_TO\*

**URL:** <https://www.ruby-forum.com/t/rerouting-between-controllers-actions-without-redirect-to/171749>\
**Category:** Rails\
**Created:** [July 8, 2009, 4:24pm UTC](https://www.ruby-forum.com/t/rerouting-between-controllers-actions-without-redirect-to/171749 "2009-07-08T16:24:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![olistik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9de0a6/32.png) [@olistik](https://www.ruby-forum.com/u/olistik)\
**Post date:** [July 8, 2009, 4:24pm UTC](https://www.ruby-forum.com/t/rerouting-between-controllers-actions-without-redirect-to/171749/1 "2009-07-08T16:24:37Z")

</div>

Hello everyone, I need to implement first level permalink style url  
routing inside my rails application, ie:  
/first\_link.html  
/another\_one.html  
…  
/last\_one.html

For each permalink there’s an associated record (model: Permalink) so  
that:  
permalink = Permalink.find\_by\_url(“first\_link.html”)

# the following gives me the action and controller associated to the

permalink  
permalink.app\_action  
permalink.app\_action.app\_controller

to handle the routing of these permalinks I’m forced to use this,  
inside my routes.rb:  
map.connect(’:permalink.html’, :controller =\> “permalinks”, :action =\>  
“drive”)

class PermalinksController \< ApplicationController  
def drive()  
permalink = Permalink.find\_by\_url(params[:permalink])

# TODO HERE

end  
end

the entire site is based on these kind of permalinks, so I’d like to  
reroute the execution flow from Permalinks::drive() to the  
controller’s action specified by the selected permalink.

The only constraint I can’t avoid is that I can’t use redirect\_to  
because it would rewrite the browser’s url and I need to keep the same  
url for the entire request.

How can I achieve this?

(I hope this will be a builtin feature )

Thx@ll

---

<div class="post-metadata">

**Author:** ![olistik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9de0a6/32.png) [@olistik](https://www.ruby-forum.com/u/olistik)\
**Post date:** [July 8, 2009, 4:28pm UTC](https://www.ruby-forum.com/t/rerouting-between-controllers-actions-without-redirect-to/171749/2 "2009-07-08T16:28:42Z")

</div>

Well, that’s isn’t something easy to get going 🙂

What you need to do is remove this “permalink” controller and  
implement the urls using permalinks for each model/controller pair  
that requires them.

- 

Maurício Linhares  
[http://codeshooter.wordpress.com/](http://codeshooter.wordpress.com/) | [http://twitter.com/mauriciojr](http://twitter.com/mauriciojr)

On Wed, Jul 8, 2009 at 5:46 AM, maurizio de

---

<div class="post-metadata">

**Author:** ![olistik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9de0a6/32.png) [@olistik](https://www.ruby-forum.com/u/olistik)\
**Post date:** [July 9, 2009, 4:39am UTC](https://www.ruby-forum.com/t/rerouting-between-controllers-actions-without-redirect-to/171749/3 "2009-07-09T04:39:46Z")

</div>

Quoting maurizio de magnis [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> # the following gives me the action and controller associated to the permalink
> 
> # TODO HERE
> 
> How can I achieve this?

I’ve not tried it, but can Ruby proc objects be serialized? If so, just  
store  
the appropriate method call, and call it after setting params[].

HTH,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![olistik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9de0a6/32.png) [@olistik](https://www.ruby-forum.com/u/olistik)\
**Post date:** [July 9, 2009, 9:20am UTC](https://www.ruby-forum.com/t/rerouting-between-controllers-actions-without-redirect-to/171749/4 "2009-07-09T09:20:08Z")

</div>

Unfortunately this solution can’t be adopted since one of my  
constraints is to avoid having nested directories in the url, so I  
can’t use something like /mycontroller/my\_link.html, I’m forced to use  
/my\_link\_about\_my\_controller.html instead.

And don’t be fooled by the pattern I’ve just used! Urls get generated  
in an unpredictable (by routes.rb) way.

One solution I’m currently trying is by adopting “apotomo” plugin  
which is based upon the “cells” plugin.

The latter, which is extremely simple, could’ve solved my problem but  
the first is even more powerful so I’m digging in with that 😉

thx for sharing your thoughts btw 🙂

2009/7/8 Maurício Linhares [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![olistik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9de0a6/32.png) [@olistik](https://www.ruby-forum.com/u/olistik)\
**Post date:** [July 9, 2009, 4:58am UTC](https://www.ruby-forum.com/t/rerouting-between-controllers-actions-without-redirect-to/171749/5 "2009-07-09T04:58:28Z")

</div>

Nops, procs can’t be serialized, but you could (at your own risk)  
serialize a string with the code and then eval it.

- 

Maurício Linhares  
[http://codeshooter.wordpress.com/](http://codeshooter.wordpress.com/) | [http://twitter.com/mauriciojr](http://twitter.com/mauriciojr)
