aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/routing.textile
diff options
context:
space:
mode:
authorHenrik N <henrik@nyh.se>2012-03-28 21:05:46 +0200
committerHenrik N <henrik@nyh.se>2012-03-28 21:07:12 +0200
commit4a26b22b462eeaa363245d4251259d94f4f2a9ce (patch)
tree15feed16fe37c3505a26f1564435a9cb3dd3b2d5 /guides/source/routing.textile
parent6410d2122069a7eced244daacc7fbd033a3c34f9 (diff)
downloadrails-4a26b22b462eeaa363245d4251259d94f4f2a9ce.tar.gz
rails-4a26b22b462eeaa363245d4251259d94f4f2a9ce.tar.bz2
rails-4a26b22b462eeaa363245d4251259d94f4f2a9ce.zip
Routing guide: document lambda constraints and request argument.
Diffstat (limited to 'guides/source/routing.textile')
-rw-r--r--guides/source/routing.textile11
1 files changed, 11 insertions, 0 deletions
diff --git a/guides/source/routing.textile b/guides/source/routing.textile
index e93b1280e0..78d1783610 100644
--- a/guides/source/routing.textile
+++ b/guides/source/routing.textile
@@ -535,6 +535,17 @@ TwitterClone::Application.routes.draw do
end
</ruby>
+You can also specify constraints as a lambda:
+
+<ruby>
+TwitterClone::Application.routes.draw do
+ match "*path" => "blacklist#index",
+ :constraints => lambda { |request| Blacklist.retrieve_ips.include?(request.remote_ip) }
+end
+</ruby>
+
+The +matches?+ method or the lambda is passed the "+request+ object":http://guides.rubyonrails.org/action_controller_overview.html#the-request-object, which means the constraint can check +request.path_parameters+, +request.headers+ or any other property of the request.
+
h4. Route Globbing
Route globbing is a way to specify that a particular parameter should be matched to all the remaining parts of a route. For example