Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在“中绕过圆点”;“漂亮的URL”;_Ruby On Rails_Routes_Actioncontroller - Fatal编程技术网

Ruby on rails 在“中绕过圆点”;“漂亮的URL”;

Ruby on rails 在“中绕过圆点”;“漂亮的URL”;,ruby-on-rails,routes,actioncontroller,Ruby On Rails,Routes,Actioncontroller,在我的routes.rb中,我有: map.connect ':name', :controller => 'my_classes', :action => 'show' 这非常有效,所以像这样的url发送如下参数: http://localhost:30000/awesome Parameters: {"name"=>"awesome"} 但是如果我有这样的错误: http://localhost:30000/weak.sa

在我的routes.rb中,我有:

map.connect ':name',
            :controller => 'my_classes',
            :action => 'show'
这非常有效,所以像这样的url发送如下参数:

http://localhost:30000/awesome
Parameters: {"name"=>"awesome"}
但是如果我有这样的错误:

http://localhost:30000/weak.sauce
ActionController::RoutingError (No route matches "/weak.sauce" with {:method=>:get}):
我怎样才能避开这个问题呢?

你可以试试

map.connect ':name',
            :controller => 'my_classes',
            :action => 'show',
            :name => /[a-zA-Z\.]+/

或者使用任意正则表达式作为名称。(我建议的一个应该匹配任何字母或点组合-
弱.酱汁
弱…酱汁
弱.酱汁
,等等)

完美。我真的需要花一周时间研究正则表达式,我有一种预感,解决方案会包括它们。在正则表达式中,您可能希望转义“.”like so:\。因为点位于字符类中,所以不需要转义。仍然逃避也不会伤害任何东西。是的,我忘了(伸手去拿咖啡;-)