All threads / How do I update a user to admin in production?
Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I update a user to admin in production?

Jack asked in Rails

Simple question I guess. But how do I update a user to admin in production?

I have a pretty basic setup (no admin gems). The user model has a is_admin boolean field with the default being FALSE. In development I just update the field to TRUE with the terminal. Is it fine doing this in production or is there a better flow I could build for doing this?

TL;DR; SO yeah, it depends! But don't feel bad about utilizing rails console in production - we all do that, and it's perfectly fine!

I'd say that 100% depend on the type of app you're building. Will it have 500 admins, or just 1 or 2? If it's a very low number, updated that through the rails console is 100% a fine way to approach this. If you have MANY users that need to be admin, you could consider building some UI around this. It also depends on what you mean by admin. Does an admin user have the privileges to delete other users or records associated to other users? If that's the case i'd probably stick to doing it through rails console - if you add UI to it, you open up an attack vector. If your admin account somehow gets compromised, the attacker could make themselves admin etc etc :)

Thanks, Jesper. I think I'll use the console!

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 70,078+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.