为什么参数中带有点的路由无法匹配? [英] Why do routes with a dot in a parameter fail to match?

查看:14
本文介绍了为什么参数中带有点的路由无法匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的用户提供了一条路线,例如 /iGEL/contributions,它运行良好.但是现在一个用户注册了一个像'A.and.B.'这样的名字,现在路由无法匹配,因为名字包含点.

I've got an route for my users like /iGEL/contributions, which works fine. But now a user registered with a name like 'A.and.B.', and now the route fails to match, since the name contains dots.

我的路线:

get "/:user/contributions" => 'users#contributions'

有什么想法吗?

推荐答案

查看蓝色信息框 这里:

默认情况下,动态段不会接受点 - 这是因为点用作格式化的分隔符路线.如果您需要使用点在动态段内添加一个覆盖这个的约束——对于示例 :id =>/[^/]+/ 允许除了斜线之外的任何东西.

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 which overrides this – for example :id => /[^/]+/ allows anything except a slash.

例如:

get "/:user/contributions" => 'users#contributions', :constraints => { :user => /[^/]+/ }

这篇关于为什么参数中带有点的路由无法匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆