We have decided to add administrator privileges to the user function.
To create an admin user, I created an admin user from rails c
.
I would like other development members to create an administrator user, but considering the possibility of creating each from rails c
, it will be troublesome or forgotten, so seed I decided to create a file and have an admin user created.
This time, we will create the data of the administrator user.
under db db/seeds/admin_user.Create an rb.
Create a seed file as shown below.
#### **`db/seeds/admin_user.rb`**
```rb
User.create(admin: 1, email: "[email protected]", password: "123456")
Enter the following command in the terminal.
bundle exec rails r db/seeds/admin_user.rb
If you check the database, an admin user has been created.
You can also easily create multiple data by using the each statement in the seed file.
This is the initial data creation with seed.
Recommended Posts