0

How to add percentage and . in search string rails constrains. It's giving No route matches [GET] (Actually it's a GET Request)

Here is my constraint

get "/external_id/:external_id",
controller: "XXXXXXX",
action: "show_by_login_name",
constraints: { external_id: /[a-zA-Z0-9.]%+/ }
  • Please add link examples that you're trying to handle – Vasfed Mar 26 '19 at 13:49
  • @Vasfed For your reference http://localhost:15302/v1/internal/organizations/xxxxxxxxxx/users/external_id/test%ert http://localhost:15302/v1/internal/organizations/xxxxxxxxxx/users/external_id/test.123 http://localhost:15302/v1/internal/organizations/xxxxxxxxxx/users/external_id/test%ertt.ut – Krishna Maheswara Mar 26 '19 at 16:36

1 Answers1

3

Please modify your regex to use the following code

/[0-z\.\%]+/

Explanation:

Your current regex /[a-zA-Z0-9.]%+/ reads as:

  1. match a single character from the list: [a-zA-Z0-9.]
  2. match one or more occurrences of %

So, if your :external_id is: something%else, the pattern matches only g%.

In the future, if you are not sure about regex, you can always test it with tools such as regex101

MrShemek
  • 2,413
  • 1
  • 16
  • 20
  • The above regex will works fine but still i am getting bad request thanks for your answer. http://localhost:15302/v1/internal/organizations/xxxxxxxxxx/users/external_id/test%ert Puma caught this error: bad URI(is not URI?): "/api/organizations/xxxxxxxxxxx/users/external_id/test\u000Et" (URI::InvalidURIError) – Krishna Maheswara Mar 26 '19 at 16:31
  • @KrishnaMaheswara when you want to send `%` in the URL, please use `%25` instead (https://stackoverflow.com/a/17342786/2039726). Is it working then? – MrShemek Mar 26 '19 at 16:49