How do I remove the Devise route to sign up?

后端 未结 15 2350
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 07:36

I\'m using Devise in a Rails 3 app, but in this case, a user must be created by an existing user, who determines what permissions he/she will have.

Because of this, I

15条回答
  •  一生所求
    2020-12-07 08:23

    I had the same issue and I found it a bit bad practise to redirect users from the registration page. So my solution is basically is not using :registrable at all.

    What I did was to create a similar page like edit user details which looked like:

    <%= form_tag(update_user_update_path, method: :post) do %>  
        
    <%= label_tag(:currPassword, 'Current password:') %> <%= password_field_tag(:currPassword) %>
    <%= label_tag(:newPassword, 'New password:') %> <%= password_field_tag(:newPassword) %>
    <%= label_tag(:newPasswordConfirm, 'Confirm new password:') %> <%= password_field_tag(:newPasswordConfirm) %> 
    <%= submit_tag('Update') %> <% end %>

    So this form submits into a new post end point that updates the password, which looks like:

      def update
        currPass = params['currPassword']
        newPass1 = params['newPassword']
        newPass2 = params['newPasswordConfirm']
        currentUserParams = Hash.new()
        currentUserParams[:current_password] = currPass
        currentUserParams[:password] = newPass1
        currentUserParams[:password_confirmation] = newPass2
        @result = current_user.update_with_password(currentUserParams)
      end
    

    Later on you can use the @result in your view to tell the user whether the password is updated or not.

提交回复
热议问题