Two RESTful routes to same controller - best way to implement

I have a controller that needs to render two different layouts depending on the current path, but otherwise performs all the same actions.

The routes for the controller are:

/bars /foos/5/bars

Both need to call the same controller. The rub, however, is that in my views I don't want to use logic everywhere to determine which named route to call depending on whether @current_foo is set (the id of the current foo). Right now I have many bars_url() and bar_url(@current_bar) routes - these should generate the proper route based on whether the current path is /foos/:id/ or just /.

The only solution I see is to override all the named routes for 'bar' in a helper, and include that helper in my application controller (since these routes are used in controllers as well), but that doesn't seem a clean solution.

Is there any way to do this?

Thanks for the reply, but we already implemented everything that does. I'm asking more about the actual routes - having two routes of the same name doesn't work, so is there a way to add some logic to determine which route to use based on the value of an instance variable?

As a further example, to accomplish two routes to same the controller, you usually have to do a name_prefix:

so /bars is bars_url /foo/5/bars is foo_bars_url

I want to just use bars_url everywhere - shouldn't there be a way to determine which route to use based on whether a parameter us set in the current path?