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 Jones On Sep 23, 3:48 am, harm <harmaa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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
Matt Jones 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 marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
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- s.net> wrote:> Matt Jones 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-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/.