rails nested resources handle edit path as id
I have the following routes
resources :users, path: '/' do
resources :posts, path: '/'
end
the problem is that th开发者_如何学编程e inner route override the outer route for user's edit path.
http://localhost/user/edit refer to posts#show instead users#edit
EDIT
Singular resource is not the solution, I want to access the user via his ID.
lets say I have user with id "Jo" and post with id "My-First-Post", then the corresponding route should be http://localhost/Jo/My-First-Post. that's work just fine with my current solution.
the problem is that when I access /Jo/edit I get exception that there is no post with id "edit" while I want this route to refer to Jo's edit page (users#edit)
What are you trying to achieve? It sort of looks like you want a singular resource. If that's the case, you can just do:
routes.rb
resource :user
So just make the word resource
and user
singular. Then you'll get singular routes, like user/edit
.
See the Rails guide for more information: http://guides.rubyonrails.org/routing.html#singular-resources
精彩评论