ShayDavidson
ShayDavidson

Reputation: 781

How can I skip an after_filter callback based on my response status code in Rails?

I have an after_filter in one of my controllers that I want to execute only if the response status code is 200. Otherwise I want to skip it. Is that possible?

Upvotes: 2

Views: 749

Answers (1)

MurifoX
MurifoX

Reputation: 15089

A quick and easy way is to put a conditional on your after_filter like this:

after_filter :do_something

def do_something
  if response.code == '200'
    # do something
  end
end

Upvotes: 6

Related Questions