cdotfeli
cdotfeli

Reputation: 309

Allow users to create other users in Devise?

Sort of a Rails beginner here.. My application uses Devise for authentication. What I need it to do is allow users, once signed in, to create other users that belong to the same organization as him.

Problem is I can't just use the default Devise new registration form since it doesn't allow me to access it when I'm signed in (I'm thinking I can override this by generating my own User controller?).

Plus, the user table has an organization_id (automatically created on signup) and I need the form to pass the current_user.organization_id for organization_id, and the default form won't let me do that.

Any suggestions?

Upvotes: 4

Views: 1296

Answers (1)

Jasdeep Singh
Jasdeep Singh

Reputation: 3326

You'll have to create a custom form that'll have all the required user fields and pass the form values to one of your controllers which will take the params something like this:

def create
    User.create!({:email => params[:email], :roles => ["role/organization here"], :password => params[:password], :password_confirmation => params[:password_confirmation] })
end

In addition to this you should secure this action with one of the before_filter which will check if the user is currently logged in and able to create new users?

Hope that helps.

Upvotes: 4

Related Questions