Rails 3 路由约束和正则表达式
我正在寻找匹配路径中的模式 state/city
,除非状态变量等于“auth”
match '/:state/:city' => 'cities#index', :as => :state_cities, :constraints => {:state => /(?!auth)/ }
,例如 mydomain.com/fl/miami
就很好。 mydomain.com/auth/twitter
很糟糕。
我正在使用omniauth,它要求您转到/auth/twitter
进行身份验证,但是当我输入rake paths
时却找不到它。
I'm looking to match the pattern state/city
in the path, unless the state variable equals "auth"
match '/:state/:city' => 'cities#index', :as => :state_cities, :constraints => {:state => /(?!auth)/ }
For example, mydomain.com/fl/miami
is good. mydomain.com/auth/twitter
is bad.
I am using omniauth and it requires that you go to /auth/twitter
for authentication, however it is nowhere to be found when I type rake routes
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 mu is Too Short 的评论,这是我得出的答案:
lib/omniauth_pass_thru.rb
Based on mu is too short's comments, here is the answer I've come up with:
lib/omniauth_pass_thru.rb
您应该能够在州/城市路线之前定义
/auth
路线:因此,这个命令应该做正确的事情:
您可能希望通过将州/城市路线放入它们自己的命名空间中来完全避免问题:
这为将来的其他用途留下了顶层。
You should be able to define your
/auth
route before your state/city routes:So this order should do the right thing:
You might want to avoid the problem altogether by putting your state/city routes into their own namespace:
That leaves the top level clear for other future uses.