Routes requirements exclude one character

Hi!

Consider the following route:
map.detail “subscription_plans/:provider/:plan”, :action =>
“detail”, :requirements => {:plan => /[^ ]+/}

I want this route to match any string without a space character. So
“Telfort-100” matches “Telfort 100” does not.

I believed this to be correct but it’s not. Including anchors (’\A’
‘$’ etc) is not allowed. How else can I fix this?

Harm

The regexp you’ve specified here will match as long as there are at
least two consecutive non-space characters. The only way I can think
of to do what you’re looking for would be to add a route preceding
this one which matches any :plan WITH a space, and routes it to an
error page. EG:

map.bad_detail “subscription_plans/:provider/:plan”, :action =>
‘detail_error’, :requirements => { :plan => /[ ]/ }
map.detail “subscription_plans/:provider/:plan”, :action => ‘detail’

–Matt J.

Matt J. wrote:

The regexp you’ve specified here will match as long as there are at
least two consecutive non-space characters.

I would have thought so, but the routing docs suggest that the regex is
implicitly anchored at both ends (look at the postalcode example).

The only way I can think
of to do what you’re looking for would be to add a route preceding
this one which matches any :plan WITH a space, and routes it to an
error page.

That’s clever!

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

That is clever!

I still believe Rails is in error here. The docs indeed do suggest
that the stuff is anchored. Clearly it’s not. I’ll consider making a
ticket.

Thanks for the input guys!

On Sep 23, 10:30 pm, Marnen Laibow-Koser <rails-mailing-l…@andreas-