0
1

More than 3 years have passed since last update.

Docker内でRails cをしてadmin機能を持ったユーザを作成する方法

Last updated at Posted at 2020-04-18

以下の記事の内容のDocker版です。
https://qiita.com/geek_shanshan/items/c68befcae55c078b5a9d

管理用にadminカラムを持ったユーザーを作成したいと思いました。

前提

Rails は web で動作します。
Dockerをアプリに組み込めている状態です。

手順

$  docker-compose up -d     #コンテナを起動する

$  docker-compose exec web bash   #コンテナ内に入りbundle install、rails cなどを使える状態にする

root@コンテナID:/アプリ名#rails c    #コンソールに入る

irb(main):006:0> User.create!(name:'admin', email:'admin@example.com',  password:'admin', admin: true)   #ユーザーを作る

終わりです。

既存のユーザにアドミン権限をつける方ほはこちら。

user = User.find(1)
user.admin = true
user.save
0
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
0
1