リダイレクトを防ぐために、カスタム障害アプリを作成できます。
class CustomFailureApp < Devise::FailureApp
def respond
unless request.format.to_sym == :html
http_auth
else
redirect_to redirect_url
end
end
def http_auth
super
self.status = 401
self.content_type = 'json'
self.response_body = {
:error => 'NO MORE REDIRECT',
:status => 401
}.to_json
end
end
devise初期化子でこの失敗アプリを使用するようにWardenを構成します。
Devise.setup do |config|
...
# ==> Warden configuration
# If you want to use other strategies, that are not (yet) supported by Devise,
# you can configure them inside the config.warden block.
config.warden do |manager|
manager.failure_app = CustomFailureApp
end
end
ここに参照があります:
http://casperfabricius.com/site/2010/09/30/ajax-sign-in-and-sign-up-with-devise/