Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

When I order my resources like below, /websitename works but /username doesn't.

resources :websites, :path => '', :only => [:create, :show] do
    resources :pages, :only => [:create, :show, :edit]
end

resources :users, :path => '', :only => [:create, :show, :index]

When I reverse the order like below, /username works but /websitename doesn't.

resources :users, :path => '', :only => [:create, :show, :index]

resources :websites, :path => '', :only => [:create, :show] do
    resources :pages, :only => [:create, :show, :edit]
end

It's like one is cancelling the other out or something. Is there some way around this? Some way to encapsulate them or something? I've no idea what I'm doing...

share|improve this question
up vote 1 down vote accepted

You can only have one top level resource with no :path in practice. It will always match so nothing after will.

With command line - you can look at rake routes to see the actual url patterns each route is expecting and the precedence order.

And this makes sense, right? You wouldn't know if /georgia was a person or a place.

If your website routes have something special about them (like they all start with 'site') then you could do something like this.

resources :websites, :path => '', constraints: { id: /site+/ }

Put the more restrictive routes first in the routes file.

share|improve this answer
    
Hmmm...I see, makes sense I guess yeah. I guess I gotta think now which I want to be TL and which to hide behind the controller name :/ – colmtuite Dec 9 at 0:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.