From 4a26b22b462eeaa363245d4251259d94f4f2a9ce Mon Sep 17 00:00:00 2001 From: Henrik N Date: Wed, 28 Mar 2012 21:05:46 +0200 Subject: Routing guide: document lambda constraints and request argument. --- guides/source/routing.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'guides/source/routing.textile') 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 +You can also specify constraints as a lambda: + + +TwitterClone::Application.routes.draw do + match "*path" => "blacklist#index", + :constraints => lambda { |request| Blacklist.retrieve_ips.include?(request.remote_ip) } +end + + +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 -- cgit v1.2.3