简体   繁体   English

如何在ActiveAdmin Rails的admin_user模型中添加用户名

[英]How to add name of the user in admin_user model in ActiveAdmin Rails

I am trying to add a new field called username to my admin_user model. 我试图在我的admin_user模型中添加一个名为username的新字段。 I am using ActiveAdmin in my application. 我在应用程序中使用ActiveAdmin。 I am not sure how to add it? 我不确定如何添加?

You can do it using these two commands: 您可以使用以下两个命令来做到这一点:

rails generate migration add_username_to_admin_user username:string    

rake db:migrate

The first line is a shortcut for adding a field to a table ( add_username_to_admin_user ). 第一行是将字段添加到表的快捷方式( add_username_to_admin_user )。 It will produce something like this: 它将产生如下内容:

class AddUsernameToAdminUser < ActiveRecord::Migration
  def change
    add_column :admin_users, :username, :string
  end
end

The second line applies the migration to your database. 第二行将迁移应用于您的数据库。

You might also want to review the migration documentation for more in-depth information (as always, Caveat Emptor: Rails documentation is notoriously out of date). 您可能还需要查看迁移文档以获取更深入的信息(一如既往,Caveat Emptor:Rails文档已经过时了)。

您需要将其添加到架构中(使用rails g migration ),更新数据库( rake db:migrate ),然后活动的管理员将看到该字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM