Well, finally, the throttle is a good solution.
You can do it as follows. You need to define your custom delimiter. It can be based on any of the following restrictions:
Rack::Throttle::Limiter Rack::Throttle::Interval Rack::Throttle::Hourly Rack::Throttle::Daily
All you have to do is infer from one of the above classes in order to define custom logic. For example:
class CustomLimiter < Rack::Throttle::Interval def allowed?(request)
You must put this file in the path RAILS_ROOT/lib . Then, in the application.rb file, you must specify which class to use as the limiter. For example, if you want to apply a limiter to only one action, you can do it like this:
#lib/custom_limiter.rb class CustomLimiter < Rack::Throttle::Interval def allowed?(request) path_info = Rails.application.routes.recognize_path request.url rescue {} if path_info[:controller] == "application" and path_info[:action] == "check_answer" super else true end end end
You may need to take this into account.
I hope it will be useful
UPD:
you can check another solution: rack-attack
RomanKapitonov
source share