I want to make first user became admin.
So I have string attribute admin and I need to make some before filter or override Devise registration controller. Something like:
if User.first?
User.admin = "admin"
User.save
end
Here is devise regitration action
def new
resource = build_resource({})
respond_with resource
end
What would be the better way to do this ?
Assuming your code is not running very often (only when running your app in production for the first time) I would simply write a Rake task that does this for you once instead of cluttering your application code.
Put this in your
RakefileThis way you keep your code clean while still having a very easy way to promote the first user during installation.
If you want to promote the first user you simply run
rake promote_adminfrom the console and the first User will be promoted to admin.