Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect in Rails after_filter whether we're rendering or redirecting

I'm writing an after_filter in Rails 3, and I'd like to detect whether or not the controller (or any other filter) has issued a redirect. Is there any way to do this?

like image 284
Paul A Jungwirth Avatar asked May 30 '11 20:05

Paul A Jungwirth


Video Answer


1 Answers

You could look at the status code. 200 is a render, 302 is a redirect.

after_filter :what_happened

protected

def what_happened
  was_redirect = self.status == 302
  was_render = self.status == 200
end
like image 87
Douglas F Shearer Avatar answered Oct 29 '22 20:10

Douglas F Shearer