LoginSignup
2
1

More than 3 years have passed since last update.

Active Admin 管理者画面からユーザー作成できない

Last updated at Posted at 2020-07-25

経緯

rails g active_admin:resource user

を実行し、

class DeviseCreateUsers < ActiveRecord::Migration[6.0]
  def change
    create_table :users do |t|

      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""
      t.string   :reset_password_token
      t.datetime :reset_password_sent_at
      t.datetime :remember_created_at
      t.timestamps null: false
    end
    add_index :users, :email,                unique: true
    add_index :users, :reset_password_token, unique: true  
  end
end

usersテーブルのカラムに合わせて

ActiveAdmin.register User do
  permit_params :email, :reset_password_token, :reset_password_sent_at, :remember_created_at
end

とpermit_paramsを書いて
ユーザーを作成する(失敗).png
フォーム入力後にユーザー作成ボタンを押したらユーザー作成できなかった。

そこでadmin_users.rbにならってuser.rbを書き換えたところ

ActiveAdmin.register User do
  permit_params :email, :password, :password_confirmation

  index do
    selectable_column
    id_column
    column :email
    column :current_sign_in_at
    column :sign_in_count
    column :created_at
    actions
  end

  filter :email
  filter :current_sign_in_at
  filter :sign_in_count
  filter :created_at

  form do |f|
    f.inputs do
      f.input :email
      f.input :password
      f.input :password_confirmation
    end
    f.actions
  end
end

以下のように表示が変わり
ユーザーを作成する(成功).png
ユーザー作成できました!

2
1
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
2
1