Anumira Technologies
Anumira Technologies

Reputation: 41

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. I am using ActiveAdmin in my application. I am not sure how to add it?

Upvotes: 0

Views: 871

Answers (2)

Misha
Misha

Reputation: 1896

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). 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).

Upvotes: 1

sorens
sorens

Reputation: 5060

You need to add it to your schema (use rails g migration), update your DB (rake db:migrate) and then active admin will see the field.

Upvotes: 0

Related Questions