views:

192

answers:

2

Hello,

Let's say we have the following pages clip/show/111 image/show/222 sound/show/333 where 111,222 and 333 are the IDs for different contributions

I developed a new controller called "show" that will detect ID and redirect to the right controller show/show/111 will redirect to clip/show/111 and so on

what I want is to render the page clip/show/111 without redirecting, meaning that the URL on the browser will still show "show/show/111" but in fact render the "clip/show/111"

How could I do that?

Thanks all Wa'el

A: 

It sounds like what you're really trying to do is make aliases for some of your routes, so you can access the same functionality from different URL structures. If that is the case, creating an entire controller that delegates all of its work to another controller would be a code smell (feature envy).

What you probably want to do is define some extra routes for "show/" that simply re-use the same Clip controller. This would be accomplished by simply doing the following:

# routes.rb
# ...
# For Rails 2
map.resources "show", :controller => "clip"

# For Rails 3
resources "show", :controller => "clip"
Chris
Also I know you said you didn't want to redirect, but it's worth mentioning that the Rails 3 router allows you to redirect directly from the routes.rb file. Check out http://guides.rubyonrails.org/routing.html#redirection for more info.
Chris
I cant use resources like that since routes dont know the contribution type if it was clip, image ..etc, In my show controller I make certain queries to know the type of ID passed and render the controller/action accordingly.
wael34218