[RUBY] Implement devise edit page

I had a hard time because I couldn't create a user information editing function in Rails. I will share it because the cause has been clarified.

Development environment

Rails 6.0.3.3 devise 4.7.3

problem

--Data is not sent when you press the send button --The nickname column cannot be updated

Cause

--I made a mistake in the default devise / registrations / edit.html.erb. --You have not set the controller and routing to add columns other than the columns that exist by default.

View

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>

Correctly, it is described using form_for as above, but when setting the display of the view to an arbitrary form, it was mistakenly changed to the form using form_with. Therefore, the update was not performed in the form registered in devise by default, and the update could not be performed.

<%= f.label "nickname"%>
<%= f.text_field :nickname, autofocus: true%>

In addition, the form was described in the above form for adding the nickname column. You can enter it, but it will not be updated.

routing

devise_for :users, controllers: {
 registrations: 'users/registrations'

Added the above description

controller

Do the following in the terminal

 % rails g devise:controllers users

Running via Spring preloader in process 39712
      create  app/controllers/users/confirmations_controller.rb
      create  app/controllers/users/passwords_controller.rb
      create  app/controllers/users/registrations_controller.rb
      create  app/controllers/users/sessions_controller.rb
      create  app/controllers/users/unlocks_controller.rb
      create  app/controllers/users/omniauth_callbacks_controller.rb

After that, add the following in controllers / users / registrations_controller.rb (Since it has already been described, you can just uncomment it)

  before_action :configure_account_update_params, only: [:update]


  protected

  def configure_account_update_params
    devise_parameter_sanitizer.permit(:account_update, keys: [:nickname])
  end

Set any column in keys: [: nickname].

reference

https://qiita.com/akasakas/items/138c29fa2cecd271cfe4 https://remonote.jp/rails-devise-profile-edit

Recommended Posts

Implement devise edit page
Implement user edit / update function without using devise
Edit user information with Devise
[Rails] [Devise] Edit profile without password
Create My Page with Rails devise
[rails] Edit of view page created by devise is not reflected