在"漂亮的url "中找到点

时间:2022-02-25 16:53:11

In my routes.rb I've got:

在我的路线。rb我有:

map.connect ':name',
            :controller => 'my_classes',
            :action => 'show'

And that works perfectly, so a url like this sends params like so:

它工作得很好,像这样的url会发送这样的参数:

http://localhost:30000/awesome
Parameters: {"name"=>"awesome"}

But if I have something like this I get this error:

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

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

How can I get around this?

我怎样才能避开这个问题呢?

1 个解决方案

#1


5  

You could try

你可以试试

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

or use whatever regular expression you want for the name. (The one I suggested should match any letter or dot combination - weak.sauce, weak...sauce, .weak.sauce., etc.)

或者使用您想要的名称的任何正则表达式。(我建议的那个应该匹配任何字母或点组合-弱。酱,弱……酱,.weak.sauce。等)。

#1


5  

You could try

你可以试试

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

or use whatever regular expression you want for the name. (The one I suggested should match any letter or dot combination - weak.sauce, weak...sauce, .weak.sauce., etc.)

或者使用您想要的名称的任何正则表达式。(我建议的那个应该匹配任何字母或点组合-弱。酱,弱……酱,.weak.sauce。等)。