Reputation: 3164
I'm trying to create a route that allows anything with "-review" in the static segment :url_key. The urls I am working with may have any text before or after the substring -review in the static segment. I've seen examples for allowing integers only, but I'm not very familiar with regex syntax and I'm not quite sure how to write the constraint. Here is what I have so far.
get '/:url_key', to: 'reviews#review', constraint: { url_key: "(anything before)-review(anything after)" }
Upvotes: 0
Views: 41
Reputation: 5345
Try this:
get '/:url_key', to: 'reviews#review', constraints: { url_key: /.*-review.*/ }
If you want to ensure at least one character before the -review part, use this regex instead:
/.+-review.*/
Upvotes: 1