David
David

Reputation: 7303

Ruby-on-Rails: Devise custom failure app problem

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 #<CustomFailure:0x000001031f6220>

and it points to the respond_to do |format| line

What am I doing wrong?

Upvotes: 3

Views: 2969

Answers (1)

Sigurd
Sigurd

Reputation: 7953

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

Upvotes: 7

Related Questions