2017-05-06 80 views
0

我有一个像这样的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 
+0

你得到这个工作吗? –

+0

不,我最终使用'post':uid/links /:id'来:“links#restore”,如:“restore_link”'在资源块外 – Tsao

+0

我想自定义perfix不是url路径 – Tsao

回答

2
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