Set flash error from Rack::Attack response?

441 Views Asked by At

I'm trying to set a flash[:error] to give feedback to the user. I haven't been able to find info on how to implement. One workaround I'm doing is to redirect with query params and pick that up in the controller, but it's brittle and I'm getting some errors, turbolinks sometimes makes the message render twice.

  # rack_attack.rb
  Rack::Attack.throttled_response = lambda do |env|

    headers = {
      'Location'=> "/pages/home?error=#{throttle_type}"
    }
    [301, headers, []]
  end

What's the best way to set a flash message when a user is throttled?

0

There are 0 best solutions below