2

I have the following routes, which allows for urls like /:username/:project_name

resources :users, :path => "/" do
  resources :projects, :path => "/"
end

The problem is that /:username/edit doesn't work, because it is looking for a project with the name of 'edit'.

Any way around this? Thanks!

4
  • What url structure are you trying to accomplish? Commented Jan 12, 2012 at 18:35
  • As I wrote above, I am wanting urls like '/username/project_name' and '/username/project_name_2'. The problem is that this doesn't allow for '/username/edit'. Commented Jan 12, 2012 at 18:36
  • did you try to "manually" add this route? i would add a match "/username/edit" => "users#edit" before the resource path. and by the way, this routing setup is not a good idea. it will lead to more problems on the way... Commented Jan 12, 2012 at 21:34
  • Take off the path "/" on the projects resource. Commented Jan 12, 2012 at 22:53

1 Answer 1

3

A couple ways of doing this...

1) Will give you routes like /:user_id/:id (which you wanted)

match '/:user_id/edit', :to => 'users#edit', :as => :edit_user
resources :users, :except => [:edit], :path => "/" do
  resources :projects, :path => "/"
end

2) Will give you routes like /:user_id/projects/:id (which it seems like you're avoiding)

resources :users, :path => "/" do
  resources :projects
end

I personally prefer #2 since it is cleaner and provides more knowledge about the route at a glance.

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

Comments

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.