如何在 url Rails 中编码 (.) 点

2024-04-21

我有如下所示的路线来删除/列出用户。

map.connect 'developer/:user_name/delete',:controller=>"developers",:action=>"delete",:method=>:delete  

map.connect 'developer/:user_name/list',:controller=>"developers",:action=>"list",:method=>:get

通过用 %2E 编码点来列出用户时,我可以看到成功响应

http://localhost:3000/developer/testuser%2Ehu/list

但是,当尝试删除包含点(.)的用户时,会抛出404错误。

http://localhost:3000/developer/testuser%2Ehu/delete, how to fix this issue.

阿夫迪·格林就这个主题写道:http://avdi.org/devblog/2010/06/18/rails-3-resource-routes-with-dots-or-how-to-make-a-ruby-developer-go-a-little-bit-疯狂的/ http://avdi.org/devblog/2010/06/18/rails-3-resource-routes-with-dots-or-how-to-make-a-ruby-developer-go-a-little-bit-insane/

你会想做这样的事情(完全归功于 avdi)

  resources :users, :constraints => { :id => /.*/ } do
    resources :projects
  end

该帖子的评论者说你还可以这样做:

resources :users, :id => /.*/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 url Rails 中编码 (.) 点 的相关文章

随机推荐