简体   繁体   中英

Change path_names for all of resource

How can I change a rails resource route so that each one is prepended by a parameter that needs to be passed? The tricky part however, is that the parameter needs to be passed after the controller, but before the action.

Something like so:

/posts/:type/new
/posts/:type/edit

and so on..

You probably want something like this, where you have seperate routes which route to the same controller:

namespace :posts do
  resources :public, controller: "posts"
  resources :private, controller: "posts"
end

This gives you /posts/public/* and /posts/private/* .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM