ActiveRecord::NotNullViolation in SignupController#create
Mysql2::Error: Field 'birthday' doesn't have a default value
というエラーが出ました。
class SignupController < ApplicationController def step1 @user = User.new end def step2 session[:nickname] = user_params[:nickname] session[:email] = user_params[:email] session[:password] = user_params[:password] session[:password_confirmation] = user_params[:password_confirmation] session[:family_name] = user_params[:family_name] session[:first_name] = user_params[:first_name] session[:family_name_kana] = user_params[:family_name_kana] session[:first_name_kana] = user_params[:first_name_kana] session[:birthday] = user_params[:birthday] @user = User.new end def step3 session[:postal_code] = user_params[:postal_code] session[:prefecture] = user_params[:prefecture] session[:city] = user_params[:city] session[:address] = user_params[:address] session[:apartment] = user_params[:apartment] @user = User.new end def create @user = User.new( nickname: session[:nickname], email: session[:email], password: session[:password], password_confirmation: session[:password_confirmation], family_name: session[:family_name], first_name: session[:first_name], family_name_kana: session[:family_name_kana], first_name_kana: session[:first_name_kana], birthday: session[:birthday], postal_code: session[:postal_code], prefecture: session[:prefecture], city: session[:city], address: session[:address], apartment: session[:apartment], ) if @user.save session[:id] = @user.id redirect_to done_signup_index_path else render '/signup/registration' end end def done sign_in User.find(session[:id]) unless user_signed_in? end private def user_params params.require(:user).permit(:email, :password, :password_confirmation, :nickname, :family_name, :first_name, :family_name_kana, :first_name_kana, :birthday, :postal_code, :prefecture, :city, :address, :apartment) end end
class DeviseCreateUsers < ActiveRecord::Migration[6.0] def change create_table :users do |t| ## Database authenticatable t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" t.string :nickname, null: false t.string :user_image t.text :introduction t.string :first_name, null: false t.string :family_name, null: false t.string :first_name_kana, null: false t.string :family_name_kana, null: false t.date :birthday, null: false t.string :postal_code, null: false t.integer :prefecture, null: false t.string :city, null: false t.string :address, null: false t.string :apartment ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable # t.integer :sign_in_count, default: 0, null: false # t.datetime :current_sign_in_at # t.datetime :last_sign_in_at # t.string :current_sign_in_ip # t.string :last_sign_in_ip ## Confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at t.timestamps null: false end add_index :users, :email, unique: true add_index :users, :reset_password_token, unique: true # add_index :users, :confirmation_token, unique: true # add_index :users, :unlock_token, unique: true end end
= form_for @user, url: step2_signup_index_path, method: :get, html: {class: 'first-main__box'} do |f| = f.text_field :nickname, placeholder: '例) ニックネーム' = f.email_field :email, placeholder: 'メールアドレス' = f.password_field :password, placeholder: '7文字以上' = f.password_field :password_confirmation, placeholder: '7文字以上' = f.text_field :family_name, placeholder: '例) 田中' = f.text_field :first_name, placeholder: '例) 太郎' = f.text_field :family_name_kana, placeholder: '例) タナカ' = f.text_field :first_name_kana, placeholder: '例) タロウ' = f.date_select :birthday, use_month_numbers: true,start_year: 1930, end_year: (Time.now.year - 10), default: Date.new(1989, 1, 1) = f.submit "住所の入力へ進む"
= form_for @user, url: signup_index_path, method: :post, html: {class: 'forth-main-wrapper__box'} do |f| = f.text_field :postal_code, placeholder: '郵便番号' = f.collection_select :prefecture, JpPrefecture::Prefecture.all, :code, :name = f.text_field :city, placeholder: '市町村' = f.text_field :address, placeholder: '番地' = f.text_field :apartment, placeholder: 'ビル名、アパート名' = f.submit "登録する"
調べてもpermitを使いましょうというのばかりですでに使っているのでどこを直せばいいかわからない状態です、、
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/07/25 10:02
2020/07/25 11:21
2020/07/25 12:51
2020/07/25 23:35
2020/07/25 23:38
2020/07/25 23:40
2020/07/26 01:19
2020/07/26 02:12
2020/07/26 03:16
2020/07/26 13:22