如何设置从资源到资源的路由前缀?
问题描述:
我有一个像这样的rails路由配置,当我运行rake routes
它表明,但我想perfix是restore_link,我该怎么做?如何设置从资源到资源的路由前缀?
耙路线
restore_links POST /:uid/links/:id(.:format) links#restore
路由配置
resources :accounts, path: '/', param: :uid, only: [:show] do
member do
resources :links do
collection do
post ':id', to: "links#restore", as: "restore"
end
end
end
end
答
resources :accounts, path: '/', param: :uid, only: [:show] do
member do
resources :links, path: 'restore_links' do # <========= `path` option
collection do
post ':id', to: "links#restore", as: "restore"
end
end
end
end
你得到这个工作吗? –
不,我最终使用'post':uid/links /:id'来:“links#restore”,如:“restore_link”'在资源块外 – Tsao
我想自定义perfix不是url路径 – Tsao