2011-05-30 23 views

回答

15

您可以查看status的代碼。 200是渲染,302是重定向。

after_filter :what_happened 

protected 

def what_happened 
    was_redirect = self.status == 302 
    was_render = self.status == 200 
end 
+0

謝謝!我想我也可以檢查response.headers ['Location']。 – 2011-05-30 20:53:15

+1

「自我」中有一大堆東西,值得一看,即使只是出於興趣。 – 2011-05-30 20:53:54

0

對於任何人誰仍然停留在軌道3,並希望使用基於類的過濾器共享控制器之間的邏輯與組合,看看下面的例子:

class MyController < ApplicationController 
    after_filter ControllerMetrics 
end 

class ControllerMetrics 
    def self.filter(controller) 
    status_xxx = "#{controller.response.status/100}XX" 
    Statsd.increment("response.#{status_xxx}") 
    end 
end 
相關問題