12

I have implemented Devise in a Rails 3 application and I need admin users to be able to manage users. Users are not registerable and therefore an admin must create accounts. What would be the best way to go about this?

It doesn't seem very DRY to create my own UsersController when Devise already provides Devise::RegistrationController but I don't see any other options.

Jim Mitchener
  • 8,835
  • 7
  • 40
  • 56

2 Answers2

13

I opted to create my own UsersController along side the RegistrationController. It really makes sense to have my own RESTful controller for admin purposes. It's not devise's job to manage user records and maintain administrative fields associated with them. It is, after all, an authentication framework. It just seems correct to leave it to do what it is designed for. You are required to create your own user model for a reason.

Jim Mitchener
  • 8,835
  • 7
  • 40
  • 56
2

You can override the RegistrationController to provide the functionality you need. Check the first answer from here: Override devise registrations controller

Community
  • 1
  • 1
pushmatrix
  • 726
  • 1
  • 9
  • 23
  • Haven't tested this, but you could override the RegistrationController and simply put a before_filter in it that ensures that an admin is making the request. – pushmatrix Oct 08 '10 at 01:22
  • I actually have my own registration controller right now for authorization. My problem is that when calling sign_up as another user you are instantly logged in as that user (like it's a user registration). If I'm going to be creating all of my own methods anyway I think I'd rather just have my own UsersController – Jim Mitchener Oct 08 '10 at 12:30