Traversing Points in Good URLs

On my .rb routes, I have:

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

And this works fine, so such a url sends the following parameters:

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?

+3
source share
1 answer

You may try

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

or use any regular expression for the name. (The one that I have proposed, must comply with any combination of letters or dots - weak.sauce, weak...sauce, .weak.sauce.etc.)

+5
source

Source: https://habr.com/ru/post/1716975/


All Articles