提交 4a26b22b 编写于 作者: H Henrik N

Routing guide: document lambda constraints and request argument.

上级 6410d212
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册