Rails机架攻击宝石油门

时间:2015-11-18 11:27:33

标签: ruby-on-rails ruby-on-rails-4 rackattack

我不知道为什么我不能使用机架式攻击宝石 我在这里做了什么

的Gemfile

gem 'rack-attack' 

我安装了宝石

配置/ application.rb中

config.middleware.use Rack::Attack

初始化/机架attack.rb

class Rack::Attack

throttle('logins/ip', :limit => 5, :period => 60.seconds) do |req|
  if req.path == '/login' && req.post?
  Rails.logger.error("Rack::Attack Too many login attempts from IP: #{req.ip}")
  req.ip 
  end
end

end

的routes.rb

post   'login'   => 'index#create'
root 'index#new'
get 'login' => 'index#new'

我正在使用Rails 4.2.3和机架攻击宝石4.3.0

我想知道我错过了什么

2 个答案:

答案 0 :(得分:2)

确保在initializers / rack-attack.rb文件中配置 cache.store 您可以这样配置:

class Rack::Attack
  ...
  cache.store = ActiveSupport::Cache::MemoryStore.new
  ...
end

答案 1 :(得分:1)

You may need enable the cache in your development environment

请在config.cache_classes = true中设置config/environments/development.rb