问题在于:
当有人输入domain.com/branches/10
我需要重定向到domain.com/businesses/1/branches/10
新路线
resources :businesses do
resources :branches
end
旧路线
match 'branches/:id', to: 'branches#show'
谢谢!
答案 0 :(得分:0)
好的,我明白了:
match '/branches(/*path)' => redirect{ |params| "/businesses/#{Branch.find(params[:path]).business.to_param}/branches/#{Branch.find(params[:path]).to_param}" }
我还需要添加.to_param
,因为我最近也切换到半友好网址(id + name)。这适用于将id或友好URL转换为新的嵌套路径。