Devise: How to create a new user being already logged in?

后端 未结 8 2086
独厮守ぢ
独厮守ぢ 2021-02-02 16:22

I\'m going to create a multi user app, so, I will have a admin user that will have permission to create new ones.

I\'ve created the UsersControllerbut when

8条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 16:27

    You could either override the default devise controller and add in your custom logic, or, It would probably be easier however to make a new (Admin) controller and simply create a user using one of it's actions.

    @user = User.create!(:name => params[:foo], :email => params[:bar])
    redirect_to @user
    

    Devise has loads of guides on how to customise it's behaviour here: https://github.com/plataformatec/devise/wiki/_pages

    This one in particular may be of interest to you: https://github.com/plataformatec/devise/wiki/How-To:-Manage-Users-with-an-Admin-Role-(CanCan-method) But make sure to have a look over the rest of the articles, there's a lot of them.

提交回复
热议问题