views:

136

answers:

1

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?

+5  A: 

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

Vinay Sajip
Perfect. I really need to spend a week on regular expressions, I had a hunch the solution would include them.
rpflo
in the regular expression you might want to escape the "." like so: \.
Valters Vingolds
@valters: Thanks, corrected it.
Vinay Sajip
Since the dot is within a character class it doesn't need to be escaped. Still escaping it won't hurt anything either.
Andrew Hare
True, I forgot (reaches for coffee ;-)
Vinay Sajip