Merge pull request #402 from collimarco/patch-1

Add example: Match Actions in Rails
This commit is contained in:
Gonzalo Rodriguez 2019-02-21 22:24:45 -03:00 committed by GitHub
commit 9e90b20122
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -90,4 +90,20 @@ Rack::Attack.blocklist('basic auth crackers') do |req|
auth.credentials != [my_username, my_password]
end
end
```
```
### Match Actions in Rails
Instead of matching the URL with complex regex, it can be much easier to mach specific controller actions:
```ruby
Rack::Attack.safelist('unlimited requests') do |request|
safelist = [
'controller#action',
'another_controller#another_action'
]
route = (Rails.application.routes.recognize_path request.url rescue {}) || {}
action = "#{route[:controller]}##{route[:action]}"
safelist.any? { |safe| action == safe }
end
```