Search code examples
ruby-on-railsroutesactioncontroller

Getting around dots in "pretty urls"


In my routes.rb I've got:

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

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

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?


Solution

  • 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.)