Skip to content

Commit

Permalink
Be explicit about allowed constraint values, fixes #14702
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuchal committed Apr 11, 2014
1 parent 1424482 commit aca64fe
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions guides/source/routing.md
Expand Up @@ -694,6 +694,8 @@ namespace :admin do
end
```

NOTE: Request constraints work by calling a method on the <a href="action_controller_overview.html#the-request-object">Request object</a> with the same name as the hash key and then compare the return value with the hash value. Therefore, constraint values should match the corresponding Request object method return type. For example: `constraints: { subdomain: 'api' }` will match an `api` subdomain as expected, however using a symbol `constraints: { subdomain: :api }` will not, because `request.subdomain` returns `'api'` as a String.

### Advanced Constraints

If you have a more advanced constraint, you can provide an object that responds to `matches?` that Rails should use. Let's say you wanted to route all users on a blacklist to the `BlacklistController`. You could do:
Expand Down

0 comments on commit aca64fe

Please sign in to comment.