开发者

rails nested resources handle edit path as id

开发者 https://www.devze.com 2023-04-01 12:08 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消