Forum: Ruby on Rails Routing Resources to two different places

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D95ca6160a41d5ae04a60662c4351f95?d=identicon&s=25 Brent Dillingham (Guest)
on 2007-07-10 19:06
(Received via mailing list)
Hi folks,

Here's the deal:

I've got an Article model and an ArticlesController with a set of
templates that I like so much, I need to share it with different parts
of the site which have different URL's. I'm using REST for the

So at the top-level of the site, I might have something like:

map.resources :articles, :path_prefix => "news"

I also have many "subsites" of my domain which need news articles,

map.resources :articles, :path_prefix => ":subsite/news", :name_prefix
=> "subsite_"

So, yeah, this would work out OK. But this means that in my Article
templates when I'm calling the named routes, I'd probably have to make
a helper method like:

def article_path_helper(path, subsite = false)
  if subsite
    send('subsite_' + path, :subsite => subsite)

So as an example in my Article templates:
article_path_helper('edit_article_path', @subsite)

@subsite would get set by some logic in the controller if we're routed
from a subsite URL, otherwise it's false.

Maybe it's my inexperience, but this seems dirty and like I'm doing
something wrong. Are the named routes provided by the REST stuff worth
using in this case? Maybe I should ignore the named routes and use
url_for instead, if that would make things any easier.. not sure.

I tried to keep this brief, but can elaborate if needed... hope it's
clear enough. I'd love to have anyone's thoughts on solving this
particular problem.
This topic is locked and can not be replied to.