4

ラックアタックを使っています。誰かが制限を超えた場合、私は次のコードを使用しています:

Rack::Attack.throttled_response = lambda do |env|
  [429, {}, [ActionView::Base.new.render(file: 'public/429.html')]]
end

sby が POST リクエストの制限を超えた場合、元のレスポンスは正常respond_to :html429.html動作します。応答する POST リクエストが制限を超えたrespond_to :js場合、画面には何も表示されませんが、ログを確認するとすべて問題ないようです。

Rendered public/429.html (1.4ms)

429.htmlの場合はどうすれば表示できjs responseますか?error messagesどうにかしてこのラックコードからRailsアプリに引き継ぐことは可能でしょうか? それほど複雑でない場合は、error messagesからに変更する場合があります。rendering

4

1 に答える 1

7
Rack::Attack.throttled_response = lambda do |env|
  html = ActionView::Base.new.render(file: 'public/429.html')
  [503, {'Content-Type' => 'text/html'}, [html]]
end

2 番目のパラメーターで任意の応答コンテンツ タイプを設定できます。

于 2016-09-20T06:39:30.697 に答える