Forum: Ruby on Rails Single URL/route --> Different controller/action routing. Is this possible?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C56c078159148c1e3ac494ad8a7a74e0?d=identicon&s=25 raghus (Guest)
on 2008-12-03 03:38
(Received via mailing list)
I am on Rails 2.0.2

I've set up routes.rb  so that the URL 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

Thanks
5170ca260dbd2cdfd5a887a4dba7636f?d=identicon&s=25 Jeremy Weiskotten (jeremy_weiskotten)
on 2008-12-03 03:50
raghus wrote:
> I am on Rails 2.0.2
>
> I've set up routes.rb  so that the URL 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
>
> Thanks

You can call any method from that action, including the code for another
action, and then explicitly render whatever template you want.
C56c078159148c1e3ac494ad8a7a74e0?d=identicon&s=25 raghus (Guest)
on 2008-12-08 08:23
(Received via mailing list)
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-
7855792dbc5f3b4c365344314e2b1ad6?d=identicon&s=25 AndyV (Guest)
on 2008-12-08 13:59
(Received via mailing list)
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.
C56c078159148c1e3ac494ad8a7a74e0?d=identicon&s=25 Raghu Srinivasan (Guest)
on 2008-12-08 18:09
(Received via mailing list)
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
This topic is locked and can not be replied to.