When changing user information using devise Settings on the edit screen when the password is not saved

When editing user registration information using devise, the solution when the error message on the view screen is displayed as Current password can't be blank when editing → update is performed and the edit screen is not saved.

ruby '2.6.5' rails '6.0.0 devise 4.7.2

If you have an account with two devises and want to edit the user registration information and save it, we will summarize the setting flow.

(1) Check the routings / edit path of user in rails routes.

edit_user_registration GET    /users/edit(.:format)                                                          users/registrations#edit

I was able to confirm that it was edit_user_registration_path. Create a path for this with link_to.

(2) Controllers / users / registrations_controller.rb file.

Set before_action and configure_account_update_params. This time I will put my column.

before_action :configure_account_update_params, only: [:update]
def configure_account_update_params
    devise_parameter_sanitizer.permit(:account_update,  keys: [:nickname, :email, :password, :gender_id, :birth, :bloodtype_id, :emergencyperson, :emergencycall, :real_name, :real_name_kana, :phone_number])
  end
③ Next is the view.

Create an edit.html.erb file in users / registrations. I mostly use a copy of new.html.erb, but there are some additional notes. I'm using two devises so the directories are different, but with one devise the view will create edit.html.erb in devise / registrations.

Also change the path of form_with. Reference site here From the conclusion, it is the default setting of devise, but when updating the password, the current password is authenticated and updated.

<%= form_with model: @user, url: user_registration_path, method: :patch, class: 'registration-main', local: true do |f| %>
 <div class="field">
    <%= f.label :current_password %> 
    <%= f.password_field :current_password, autocomplete: "current-password" %>
  </div>

Add this. When editing, you need an item to enter the password so far.

By adding this, the changed items were saved successfully. However, it is essential even if you do not change the password, so what is that? It's like that. I will continue to research and learn.

Recommended Posts

When changing user information using devise Settings on the edit screen when the password is not saved
[Rails 5] How to display the password change screen when using devise
[Rails] When the layout change of devise is not reflected
Edit user information with Devise
6 points to doubt when user registration is not possible with devise
How the website is displayed on the screen
[Twitter API] Countermeasures when "It is not safe" appears on the https site
Implement user edit / update function without using devise
The devise error message is not displayed properly.
When the project is not displayed in eclipse
[Android Studio] About the matter that the design view is not displayed when using TextClock