当用户名中有@符号时,Rails,route_path会中断
每当用户名中包含@
符号时,我会收到RoutingError:
No route matches {:controller=>"users", :action=>"show", :username=>"abc@shin.com"}
我的路线看起来像这样:
match 'users/:username' => 'users#show', :as => :show_other_user
我的观点是:
user.username) %>
如果用户名没有@
符号,一切正常。
因为@
,你的路线没有破坏,因为它正在打破.
。 Rails会看到.
并认为你正在尝试指定一种格式(即.html
, .xml
,…)。 你需要通过这样的方式更新你的路线来自动解决自动格式检测的问题:
match 'users/:username' => 'users#show', :as => :show_other_user, :constraints => { :username => /.*/ }
:constraints
应该解决你的路由问题(你使用:requirements
Rails 2的:requirements
)。