Getting HTTP response code from a controller

You'll have to hook it somewhere else (eg, in Mongrel or a monkey/
mixin patch to ActionController::Base). Your controller won't be
consulted in the case of a 404 or 500 error. Those are usually
generated from exceptions.

Is there a reason you need to know about these status codes in your

Cool, I could have a use for that as well. Let me know if you guys
figure it out. In the meantime I'll try to do it too.

Here's a first stab...

# lib/final_response.rb
module FinalResponse
  def self.included(base)
    base.class_eval do
      alias_method :process_without_final_response, :process
      alias_method :process, :process_with_final_response

  def process_with_final_response(*args)
    final_response if respond_to?(:final_response)

# app/controllers/my_controller.rb
class MyController < ActionController::Base
  include FinalResponse
  def final_response"status = #{headers['Status']}")

  def action

Your final_response method won't have access to the session, but
you'll still be OK to access models.

There's probably a better way to do this, but this should work...