# Single URL/route --\> Different controller/action routing. Is this possible?

**URL:** <https://www.ruby-forum.com/t/single-url-route-different-controller-action-routing-is-this-possible/154704>\
**Category:** Rails\
**Created:** [December 3, 2008, 3:38am UTC](https://www.ruby-forum.com/t/single-url-route-different-controller-action-routing-is-this-possible/154704 "2008-12-03T03:38:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [December 3, 2008, 3:38am UTC](https://www.ruby-forum.com/t/single-url-route-different-controller-action-routing-is-this-possible/154704/1 "2008-12-03T03:38:02Z")

</div>

I am on Rails 2.0.2

I’ve set up routes.rb so that the URL [http://mysite.com/username](http://mysite.com/username)  
routes the user to :controller =\> ‘foo’, :action =\> ‘bar’

However, I am rev-ing my app and based on a flag in the Users table, I  
want some users to go to :controller =\> ‘foo2’, :action =\> ‘bar2’  
while others should continue to get routed via :controller =\>  
‘foo’, :action =\> ‘bar’

Is there any way at all to do this via routes.rb? Or some other hack?  
I still want the URL to be [http://mysite.com/username](http://mysite.com/username)

Thanks

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [December 3, 2008, 3:50am UTC](https://www.ruby-forum.com/t/single-url-route-different-controller-action-routing-is-this-possible/154704/2 "2008-12-03T03:50:00Z")

</div>

raghus wrote:

> I am on Rails 2.0.2
> 
> I’ve set up routes.rb so that the URL [http://mysite.com/username](http://mysite.com/username)  
> routes the user to :controller =\> ‘foo’, :action =\> ‘bar’
> 
> However, I am rev-ing my app and based on a flag in the Users table, I  
> want some users to go to :controller =\> ‘foo2’, :action =\> ‘bar2’  
> while others should continue to get routed via :controller =\>  
> ‘foo’, :action =\> ‘bar’
> 
> Is there any way at all to do this via routes.rb? Or some other hack?  
> I still want the URL to be [http://mysite.com/username](http://mysite.com/username)
> 
> Thanks

You can call any method from that action, including the code for another  
action, and then explicitly render whatever template you want.

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [December 8, 2008, 8:23am UTC](https://www.ruby-forum.com/t/single-url-route-different-controller-action-routing-is-this-possible/154704/3 "2008-12-08T08:23:18Z")

</div>

Yes, I can call action2 in action1 in foo controller. But how about  
when I need to call action2 which is in foo2 controller? How do I get  
around that?

On Dec 2, 6:50 pm, Jeremy Weiskotten \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [December 8, 2008, 1:59pm UTC](https://www.ruby-forum.com/t/single-url-route-different-controller-action-routing-is-this-possible/154704/4 "2008-12-08T13:59:24Z")

</div>

Sounds like you want to look into using a before\_filter. The job of  
the filter would be to redirect the action2 users to action2 and allow  
the rest to default to action1.

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [December 8, 2008, 6:09pm UTC](https://www.ruby-forum.com/t/single-url-route-different-controller-action-routing-is-this-possible/154704/5 "2008-12-08T18:09:02Z")

</div>

AndyV - I could, but then some users would be _redirected_ and see a  
different URL. I’d like everyone to see the same uniform URL :  
[http://mysite.com/myusername](http://mysite.com/myusername)
