I introduced devise, but isn't there a time when this is the only column?
This time I will explain how to add columns! !!
This time we will add a name column. Execute the following command in the terminal.
$ rails g migration AddNameToUsers name:string
$ rails db:migrate
Let's edit application_controller.rb as follows. The name column is now saved when you register as a user.
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
end
end
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
<!--Let's add the corresponding description at the time of editing as follows-->
devise_parameter_sanitizer.permit(:account_update, keys: [:name])
end
end
The data is now reflected when editing: point_up_tone2:
I hope you found this article helpful: pray_tone2:
Recommended Posts