LoginSignup
8
9

More than 5 years have passed since last update.

active adminでAdminモデル以外を認証に使う方法

Last updated at Posted at 2016-02-09

ActiveAdminを利用するときに、
Admin modelを生成せず、
既存のDeviseのModelを管理者用のModelとして使いたかった。

インストール

Deviseのmodel作成をスキップ
rails generate active_admin:install --skip-users

設定の変更

http://activeadmin.info/docs/1-general-configuration.html#authentication
によると、認証で使うメソッドは、configで以下で意義されているのでそこを変更してあげると良さそう

モデル名がUserの場合

config/initializers/active_admin.rb
config.authentication_method = :authenticate_user!
config.current_user_method = :current_user
config.logout_link_path = :destroy_user_path

各メソッドは、application_controllerから呼ばれるので、
認証にdeviseを使用していない場合でも、Controller側にメソッドを定義してやれば良さそう。

結果

スクリーンショット 2016-02-09 11.46.37.png

既存のモデルを使って、認証ができました。

8
9
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
8
9