I have the following route:
get '/:id', to: 'articles#show'
How do I have the route only match if the :id
is a base64 encoded string? I've tried regexp unsuccessfully.
EDIT: I've tried using the regex suggested in one of the responses.
get /:id, to: 'articles#show', constraints: { id: /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/}
This leads to the following error in Rails:
Regexp anchor characters are not allowed in routing requirements:
/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/