#
# i hate the 'return' monkey business that rails makes you do in actions.  it
# makes code non-dry since you can never factor out a method and renders
# something, a login page perhaps, becuase you cannot call a method that
# causes another to return (well not easily).  this little bit of code
#

  class ApplicationController < ActionController::Base
    around_filter do |controller, action|
      controller.instance_eval do
        returned = catch(:render){ action.call }
        if returned == :render
          default_render unless performed?
        else
          returned
        end
      end
    end

    protected
      def render! *a, &b
        render *a, &b unless(a.empty? and b.nil?)
        throw :render, :render
      end

      def redirect_to! *a, &b
        redirect_to *a, &b
      ensure
        render!
      end

      def redirect_to_url! *a, &b
        redirect_to_url *a, &b
      ensure
        render!
      end

      def return_to! url = session[:return_to]
        redirect_to_url! url
      end
  end

#
# let's you do nice things like
#

  class ApplicationController < ActionController::Base
    protected
      def require_login
        redirect_to! login_path unless current_user
      end
  end

#
# of course you can do the same with filters, but this extends to any bit of
# code you want to factor out that needs to cause another page to be rendered
# or the current rendering cycle halted
#