我有以下路线:get '/pages/:name', to: "pages#show", as: 'page'
代表我的模型Page
。我可以自动将某个角色替换为另一个角色吗?
具体来说,如果某个网页的:name
包含字符" /",我可以自动将该字符替换为" _"或最终网址中的其他内容?
答案 0 :(得分:1)
替换
get '/pages/:name', to: "pages#show", as: 'page'
与
get '/:name', to: redirect {|path_params, _| "/pages/#{path_params[:name].gsub('/','_')}" }, as: 'page'
get '/pages/:name' => 'pages#show'