aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/routing.md
diff options
context:
space:
mode:
authorFernando Seror <ferdy89@gmail.com>2016-01-23 13:39:38 -0600
committerFernando Seror <ferdy89@gmail.com>2016-01-23 19:15:46 -0600
commit1307c8d0ea6e6c483076ee42670915bd62adf5f7 (patch)
treeda8992e7f26d004e689ac38453231b8de2b03d30 /guides/source/routing.md
parent75a8973c7afbc43d48939942247d27feb0738770 (diff)
downloadrails-1307c8d0ea6e6c483076ee42670915bd62adf5f7.tar.gz
rails-1307c8d0ea6e6c483076ee42670915bd62adf5f7.tar.bz2
rails-1307c8d0ea6e6c483076ee42670915bd62adf5f7.zip
Update the exception of format constraint in routes
Per https://github.com/rails/rails/issues/20264 [ci skip]
Diffstat (limited to 'guides/source/routing.md')
-rw-r--r--guides/source/routing.md2
1 files changed, 2 insertions, 0 deletions
diff --git a/guides/source/routing.md b/guides/source/routing.md
index 09491f3c9a..5a745b10cd 100644
--- a/guides/source/routing.md
+++ b/guides/source/routing.md
@@ -706,6 +706,8 @@ end
NOTE: Request constraints work by calling a method on the [Request object](action_controller_overview.html#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.
+NOTE: There is an exception for the `format` constraint: while it's a method on the Request object, it's also an implicit optional parameter on every path. Segment constraints take precedence and the `format` constraint is only applied as such when enforced through a hash. For example, `get 'foo', constraints: { format: 'json' }` will match `GET /foo` because the format is optional by default. However, you can [use a lambda](#advanced-constraints) like in `get 'foo', constraints: lambda { |req| req.format == :json }` and the route will only match explicit JSON requests.
+
### 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: