Rails custom route with constraints - regexp anchor characters are not allowed in routing requirements
The regex anchors are ^
and $
, but they don't achieve anything here. "(Y)ou don’t need to use anchors because all routes are anchored at the start.".
So the constraint:
:constraints => { :name => /[a-zA-Z0-9_]+/ }
will do what you want - ensure the name is composed of 1 or more of those characters, and nothing else. BTW you can simplify the regex:
:constraints => { :name => /\w+/ }
In regex we have two anchors:
- Beginning of line/string
^
- End of line/string
$
Try to remove $
from the pattern and you should be good to go...