简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM