LoginSignup
3
3

More than 5 years have passed since last update.

RailsでJSON API用のバックエンドを作っていたら、ActiveAdminが 401を吐いた場合

Posted at

症状

何事も無ければ、active_adminを使っている場合、/adminにアクセスしたら、以下の様な画面が見れるはずです。

Screen Shot 2015-05-12 at 18.20.30.png

しかし、今回こんな感じになりました。

Screen Shot 2015-05-12 at 17.35.24.png

Started GET "/admin" for ::1 at 2015-05-12 18:06:23 +0900
Processing by Admin::DashboardController#index as HTML
Completed 401 Unauthorized in 0ms

原因

Deviseを認証に利用しようとして、設定ミスをしていました。

  # ==> Navigation configuration
  # Lists the formats that should be treated as navigational. Formats like
  # :html, should redirect to the sign in page when the user does not have
  # access, but formats like :xml or :json, should return 401.
  #
  # If you have any extra navigational formats, like :iphone or :mobile, you
  # should add them to the navigational formats lists.
  #
  # The "*/*" below is required to match Internet Explorer requests.
  config.navigational_formats = ['*/*', :json]

↓にしたら直りました。

  config.navigational_formats = ['*/*', :json, :html]
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3