在"漂亮的网址"中找到点

Rya*_*nce 3 routes ruby-on-rails actioncontroller

在我的routes.rb我有:

map.connect ':name',
            :controller => 'my_classes',
            :action => 'show'
Run Code Online (Sandbox Code Playgroud)

这完全有效,所以像这样的网址会发送这样的参数:

http://localhost:30000/awesome
Parameters: {"name"=>"awesome"}
Run Code Online (Sandbox Code Playgroud)

但如果我有这样的东西我得到这个错误:

http://localhost:30000/weak.sauce
ActionController::RoutingError (No route matches "/weak.sauce" with {:method=>:get}):
Run Code Online (Sandbox Code Playgroud)

我怎么能绕过这个?

Vin*_*jip 5

你可以试试

map.connect ':name',
            :controller => 'my_classes',
            :action => 'show',
            :name => /[a-zA-Z\.]+/
Run Code Online (Sandbox Code Playgroud)

或者使用你想要的正则表达式.(I所建议的一个应匹配任何字母或点组合- ,,weak.sauce 等)weak...sauce.weak.sauce.