--Install devise --Create a model --Add column to migration file --Created a form with form_with by putting the column names of the users table in f.label and f.text_field.
This is a checklist when the form is not saved in the database even if it is filled in in this state. I will omit the details of what columns exist in the users table.
Let's see if the model has strange constraints.
user.rb
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
validates :name, presence: true
validates :profile, presence: true
validates :occupation, presence: true
validates :position, presence: true
Let's see if there are any strange restrictions when creating the table.
devise_create_users.rb
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
t.string :name
t.text :profile
t.text :occupation
t.text :position
devise doesn't have strong parameters, so we'll use devise_parameter_sanitizer instead. I was missing one column. Let's review. Specifically, I forgot to allow the email column, but when I ran it in the terminal, I noticed that something was suspicious because it was ROLLBACKed after the email as shown in this image. ..
application_controller.rb
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
private
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [ :email, :encrypted_password, :name, :profile, :occupation, :position])
end
end
It doesn't matter if only one table is created, but if there are multiple tables, has_many plural, longs_to singular, etc.
In the end this was the cause. It is a column (encryped_password by default) of the users table in devise, but when you enter the password and password of form_with, you have to describe the column name as password and password_confimation respectively. This is because devise implements the ability to check if password and password_confimation are the same, and if they are the same, return an encrypted string to encrypted_password.
<%= form_with model: @user, url: user_registration_path, local: true do |f| %>
<div class="field">
<%= f.label :encryped_password, "Password (6 characters or more)" %><br />
<%= f.password_field :encryped_password, autocomplete: "new-password" %>
</div>
<div class="field">
<%= f.label :encryped_password, "Re-enter password" %><br />
<%= f.password_field :encryped_password, autocomplete: "new-password" %>
</div>
The following is omitted
<%= form_with model: @user, url: user_registration_path, local: true do |f| %>
<div class="field">
<%= f.label :password, "Password (6 characters or more)" %><br />
<%= f.password_field :password, autocomplete: "new-password" %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Re-enter password" %><br />
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</div>
The following is omitted
It happened somewhere else before, but it's possible that the software that visualizes the database (Sequel Pro in my case) was actually saved after restarting, so please check.
that's all
Recommended Posts