Ruby-on-Rails: Devise custom failure app problem-Collection of common programming errors

I am trying to set up Devise to return 401 to unauthorized API requests instead of redirects but I’m running into a boulder. This is how I am overriding it’s custom failure behavior:

class CustomFailure < Devise::FailureApp
    include ActionController::Head
    include ActionController::MimeResponds

    def respond
        respond_to do |format|
            format.html {
                super
            }
            format.any { head :status => 401}
        end
    end
end

However, I am getting this error:

undefined local variable or method `lookup_context' for #

and it points to the respond_to do |format| line

What am I doing wrong?

  1. def respond
      unless request.format.to_sym == :html
        http_auth
      else
        super
      end
    end
    

    Devise::FailureApp is inherited form ActionController::Metal which is interacting with Rack on low level, so there is no respond_to view related stuff

Originally posted 2013-11-09 21:08:15.