2016-03-25 16 views
2

私はラックアタックを使用しています。 SBYは、元の応答がrespond_to :htmlだろうPOSTリクエストの制限を超えた場合、その後429.htmlのレンダリングが正常に動作rails from html from rack

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

:誰かが制限を超えた場合、私は、次のコードを使用しています。制限がrespond_to :jsに応答POSTリクエストを超えている場合は、何も画面に起こりませんが、私は、ログをチェックアウトする場合はすべてがうまくなるようだ:

私は js responseの場合に 429.htmlを表示することができますどのように
Rendered public/429.html (1.4ms) 

?何とかこのラックコードからレールアプリにerror messagesを渡すことは可能ですか?複雑でない場合は、error messagesからrenderingに変更することがあります。

答えて

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

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