This project is archived and is in readonly mode.
router doesn't accept conditions regexp with start of line/string char
-
Trevor Turk
- Assigned user set to josh
Thanks for the second pair of eyes. I think this might be a problem with:
So, I'm going to assign to Josh. My apologies if I'm misguided on this. Thank you!
-
Andrew White
- State changed from open to invalid
You can't use regexp anchors within routing constraints as the whole route is compiled into a larger regexp that begins with \A and may end with \Z (depending on the route spec). This is always been the case even in 2.3.x.
In your gist the route regexp would be compiled as /\A\/(?:^\d)\Z/ which is a invalid regexp. Regin picks this up which is why it looks as though the problem is there.
-
Trevor Turk
Well, that's certainly a surprise! I thought that'd be a reasonable constraint.
Is there any known workaround? In either case, I think this probably warrants some documentation mentioning that it's a known issue. I'm happy to take up the cause on that front. If anyone knows of a workaround, I'd rather include that than a caveat, though. I'll give it a day or two and work up a patch if nobody responds.
Thanks!
-
Andrew White
You don't need the anchor as all routes are anchored at the start. If what you're trying to do is to make sure that if the id param starts with an number then route it to the videos controller then this will work:
match '/:id' => 'videos#show', :constraints => { :id => /\d+(?:-[-_a-zA-Z0-9]+)/ }, :as => :video match '/:id' => 'users#show', :constraints => { :id => /[a-zA-Z].*/ }, :as => :user -
Trevor Turk
Thanks again, Andrew - that really helps.
I'm adding to Neeraj's commit (thanks, BTW :)
http://github.com/lifo/docrails/commit/a2242a608e5c3057ec46ddffdd98...
...to show an example based on Andrew's suggestion:
http://github.com/lifo/docrails/commit/81e9627c7f4bad6007a5f8b5b7f5...
Please feel free to change/remove/improve this, but I think something like it is worth having.
I also wonder if might be worth providing a nicer error message in this case, if possible, since it's a known issue.
Thanks!