1

is it bad form to end up with routes that look something like this?:

resources :users
  resources :places

resources :places

Since users have many places, and there are also many places that may not be associated with a user, just curious if this is ok, will I run into route problems or db problems since places has been stated twice as a resource? Thanks!

1 Answer 1

1

yeah that's not great. Try using :shallow => true to accomplish the same effect.

resources :users, :shallow => true do
  resources :places 
end

http://archives.ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-shallow-routes/

http://apidock.com/rails/ActionController/Resources/resources

Sign up to request clarification or add additional context in comments.

3 Comments

does shallow still send more than one route to the same place? e.g. will /users/1/places/1 and /places/1 both exist?
Aren't these redundant? If you have the places ID just use /places/1. If you want to see what routes are available you can always call rake routes
the problem with this is that you still can't see all places via /places. you know a workaround for this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.