7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HerokuでActive Adminの管理者ユーザーの権限を与える

7
Last updated at Posted at 2019-05-14

はじめに

開発環境で管理者ユーザー権限を与えるには $rails console でできますが、Herokuにデプロイして、本番環境に移行した後ってどうやって設定するの??
と思ったのでその方法を共有しておこうと思います!

方法

まずは
$cd app.name
でアプリのディレクトリに移動して

をします。この時、なぜか

heroku: Press any key to open up the browser to login or q to exit:

というエラーが出てしまって何か押しても

heroku: Waiting for login... ⣷

と出てしまって先に進まないときは、

$heroku login --interactive

とするとできると思います。

パスワードなどを入れてHerokuにログインできたら、
$ heroku console

コマンドを実行してみると、

Running console on ⬢ app.name... up, run.3425 (Free)
Loading production environment (Rails 5.1.7)
irb(main):001:0>```

となり、アプリに入れます。

```irb(main):001:0>  user = User.find(1)
irb(main):002:0>  user.admin = true          
irb(main):003:0>  user.save   ```

(↑ここは開発環境の時に $rails c で管理者ユーザー権限を与えた方法と同じにしてください  )

これで、本番環境のアプリにも、指定したユーザーに管理者ユーザーの権限を与えることができます。

少しいたずらされてもちょちょいと消し去ることができるようになりました!!


### 参考文献
- Railsで管理者権限(admin)を設定するカンタンな方法は?
 - https://nyoken.com/rails-admin
- herokuでactiveadminの管理者ユーザー権限を与えるには
 - https://kossy-web-engineer.hatenablog.com/entry/2018/09/06/060801
- heroku loginコマンドを実行できません
 - https://teratail.com/questions/158511
7
8
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
7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?