Skip to content

Commit

Permalink
Routing guide: document lambda constraints and request argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
henrik committed Mar 28, 2012
1 parent 6410d21 commit 4a26b22
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions guides/source/routing.textile
Expand Up @@ -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
Expand Down

0 comments on commit 4a26b22

Please sign in to comment.