devisesをカスタムしたログイン機能の実装中のエラー

実現したいこと

・deviseを利用したログインをemail・passwordを使用せずに別途発行されているID(6桁程度のランダムな数字)と生年月日(8桁)をログインのキーとしたい。
現在、下記のようなエラーが出ておりDBに保存ができません。

前提

管理者によって各ユーザーに登録された動画の一覧ページを見られる、アプリを作成中。
ユーザー登録には上記記載の通り、各自発行されているIDと生年月日をID/passとして利用したいと思っていますが、そのユーザー登録機能実装中にエラーが出てしまいてこずっております。

開発環境

rails :ver.6.0.0
VSコード

発生している問題・エラーメッセージ

フォームからID/生年月日を入力し、新規登録ボタンを押した時点でのlogです。

Started POST "/users" for ::1 at 2023-04-23 16:34:49 +0900 Processing by Users::RegistrationsController#create as JS Parameters: {"authenticity_token"=>"WygREmMls0QOiW8B4Vvu3KXwui8N+vdxA32VEEFNFFjiboS+7HlOcaP5B0R49N5+Qj1Xk7Tbdd50b9mfTx3zfQ==", "user"=>{"patient_id"=>"510000", "birth_date"=>"19990101"}, "commit"=>"新規登録"} Rendering devise/registrations/new.html.erb within layouts/application Rendered devise/shared/_links.html.erb (Duration: 0.2ms | Allocations: 89) Rendered devise/registrations/new.html.erb within layouts/application (Duration: 1.6ms | Allocations: 1082) [Webpacker] Everything's up-to-date. Nothing to do Completed 422 Unprocessable Entity in 13ms (Views: 10.2ms | ActiveRecord: 0.0ms | Allocations: 8613)

該当のソースコード

registration_controller.rb

1class Users::RegistrationsController < Devise::RegistrationsController 2 before_action :configure_sign_up_params, if: :devise_controller? 3 4 5 private 6 def configure_sign_up_params 7 devise_parameter_sanitizer.permit(:sign_up, keys: [:patient_id, :birth_date]) 8 end 9 10end 11

user.rb

1class User < ApplicationRecord 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :validatable 6 7 validates :patient_id, presence: true 8 validates :birth_date, presence: true, format: { with: /\A[0-9]{8}\z/, message: 'is invalid' } 9 10 has_many :exercises 11end 12

new.html.erb

1<h2>ID/passを入力してください</h2> 2 3<%= form_with model: @user, url: user_registration_path, method: :post do |f| %> 4 5<div class= "contents"> 6 <div class="form-group"> 7 <%= f.text_field :patient_id, class: 'form-control', placeholder:"例) 51XXXXXX" %> 8 <%= f.text_field :birth_date, class: 'form-control', placeholder:"生年月日8桁 20100101" %> 9 </div> 10 11 <div class="actions"> 12 <%= f.submit '新規登録', class: 'btn btn-primary' %> 13 </div> 14</div> 15<% end %> 16 17<%= render "devise/shared/links" %> 18

試したこと

binding.pryも導入しましたが、使い方も深く理解でていないため、使いこなせておりません。
どこに挿入し、コンソールになにを記入すれば良いか分からず。。。
パラメーターなどの記述に間違いはないと思うのですが、なにがエラーに繋がっているのかわかりません。
初歩的な質問で申し訳ありませんが、どなたかアドバイス頂けると幸いです。

コメントを投稿

0 コメント