我希望像这样有SEO优化的网址 http://example.com/sites/1-blau.de/plans 但路径中的点导致Rails陷入困境.如何将点转换为百分比表示形式,以便它可以工作? 我的路线: resources :sites, only: [] do res
http://example.com/sites/1-blau.de/plans
但路径中的点导致Rails陷入困境.如何将点转换为百分比表示形式,以便它可以工作?
我的路线:
resources :sites, only: [] do resources :plans, only: [:index, :show] do end end
我尝试过URI.escape和CGI.escape,但都没有用.
URI.escape('a.b')=> "a.b" CGI.escape('a.b')=> "a.b"
我以为我想要什么
Foo.escape('a.b')=> "a%2Eb"使用接受点字符的约束.
get 'sites/:site_name/plans', constraints: { site_name: /[a-zA-Z0-9\.]+/ }
从doc:
By default, dynamic segments don’t accept dots – this is because the dot is used as a separator for formatted routes. If you need to use a dot within a dynamic segment, add a constraint that overrides this – for example, id: /[^/]+/ allows anything except a slash.