Я пытаюсь создать устройство для ввода имени и фамилии пользователя в базу данных, но значения не вставляются в нового пользователя
Вот вывод сервера
Started POST "/users" for 127.0.0.1 at 2020-04-16 21:14:29 -0400
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"authenticity_token"=>"5gYkDxtixNdkvQY0gFj31pLq7JEFt9vnPGFdrHg886DrjEiFVEP609sUXExl8IVwDcymqXk0zLSCT2DV1aAigg==", "user"=>{"fname"=>"John", "lname"=>"Doe", "email"=>"johndoe@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "usertype"=>"2"}, "commit"=>"Create Account"}
(0.1ms) begin transaction
User Exists? (0.2ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ? [["email", "johndoe@gmail.com"],
["LIMIT", 1]]
User Create (0.8ms) INSERT INTO "users" ("email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["email", "johndoe@gmail.edu"], ["encrypted_password", "$2a$11$nIx0QHZsX.Z.oU2wqTv4teaAG5q0TRXJCHBTEPFZrBHpKzOjq1xQ2"], ["created_at", "2020-04-17 01:14:29.854891"], ["updated_at", "2020-04-17 01:14:29.854891"]]
(12.6ms) commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 117ms (ActiveRecord: 13.7ms | Allocations: 6840)
Я хочу, чтобы пользовательский пользователь создавал fname и lname.
Вот мой application_controller
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
before_action :configure_permitted_parameters, if: :devise_controller?
def hello; end
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) do |u|
u.permit(:fname, :lname, :email, :password,
:password_confirmation, :usertype)
end
devise_parameter_sanitizer.permit(:account_update) do |u|
u.permit(:fname, :lname, :email, :password,
:password_confirmation, :current_password)
end
end
end
Редактировать: Здесь тоже моя модель пользователя.
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
attr_accessor :fname, :lname, :bdate, :usertype
end
И здесь моя схема таблицы
sqlite> .schema users
CREATE TABLE IF NOT EXISTS "users" ("id" integer NOT NULL PRIMARY KEY, "email" varchar DEFAULT '' NOT NULL, "encrypted_password" varchar DEFAULT '' NOT NULL, "reset_password_token" varchar DEFAULT NULL, "reset_password_sent_at" datetime DEFAULT NULL, "remember_created_at" datetime DEFAULT NULL, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL, "fname" varchar DEFAULT NULL, "lname" varchar DEFAULT NULL, "bdate" varchar DEFAULT NULL, "usertype" integer DEFAULT NULL);
CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email");
CREATE UNIQUE INDEX "index_users_on_reset_password_token" ON "users" ("reset_password_token");
Редактировать 2: Я пытался реструктурировать мои configure_permitted_parameters, как это предложено, но все еще не работал.
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:fname, :lname, :email, :password, :usertype])
devise_parameter_sanitizer.permit(:account_update, keys: [:fname, :lname, :email, :password, :current_password])
end
И вывод сервера при создании пользователя на пользователя / sign_up
Started POST "/users" for 127.0.0.1 at 2020-04-17 07:43:40 -0400
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"authenticity_token"=>"M5hZ4+SvyeUo2oMlGmmPY2nVv0txr6otpDIRzDP78MyJ7ym4bm8I+Obuh9HX4nGpva5cD3EqVO0gjOTNqGDTPQ==", "user"=>{"fname"=>"John", "lname"=>"Doe", "email"=>"johndoe@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "usertype"=>"2"}, "commit"=>"Create Account"}
(0.0ms) begin transaction
User Exists? (0.3ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ? [["email", "johndoe@gamil.com"],
["LIMIT", 1]]
User Create (1.2ms) INSERT INTO "users" ("email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["email", "johndoe@gamil.com"], ["encrypted_password", "$2a$11$I9/GPvJBCm7m8y.4V3/vC.ntkZQAA911CgQf3TvPlR7CGZibLnYYS"], ["created_at", "2020-04-17 11:43:41.145992"], ["updated_at", "2020-04-17 11:43:41.145992"]]
(5.3ms) commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 126ms (ActiveRecord: 6.7ms | Allocations: 6971
Редактировать 3: Моя цель - войти в sign_up, когда devise добавляет пользователя в базу данных. Я хочу, чтобы
User Create (1.1ms) INSERT INTO "users" ("email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?)
выглядело так
User Create (1.1ms) INSERT INTO "users" ("email", "encrypted_password", "created_at", "updated_at", "fname", "lname") VALUES (?, ?, ?, ?, ?, ?)