From aca64fed43d0c9eafabaf6a36c749796783c899c Mon Sep 17 00:00:00 2001 From: Jano Suchal Date: Fri, 11 Apr 2014 15:19:37 +0200 Subject: Be explicit about allowed constraint values, fixes #14702 --- guides/source/routing.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guides/source/routing.md') diff --git a/guides/source/routing.md b/guides/source/routing.md index eef618f28d..921658a71e 100644 --- a/guides/source/routing.md +++ b/guides/source/routing.md @@ -694,6 +694,8 @@ namespace :admin do end ``` +NOTE: Request constraints work by calling a method on the Request object 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: -- cgit v1.2.3