12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DBの型 〜生年月日はdate型〜

Last updated at Posted at 2019-08-26

###生年月日がDBに登録されない:frowning2:
ユーザーの新規登録の部分の生年月日の部分だけDBに登録されなかったので困ってました。
ということで備忘録メモ:writing_hand_tone1:

##困ってたこと

registration_controller.rb

def create
    @user = User.new(user_params)
    if @user.save
      sign_in(@user)
      session[:user_id] = @user.id
      redirect_to phonemumber_users_path
    else
      render 'new'
    end
  end

private
    def user_params
      params.require(:user).permit(:nickname, :email, :password, :password_confirmation, :last_name, :first_name, :first_name_kana, :last_name_kana, :birthday)
    end

ニックネームとかemailはDBに入るのにbirthdayだけ登録されない:sob:

##解決した方法
####:point_up_tone1:birthdayのカラムがstring型だったのでdate型に直した

一番最初のマイグレーションファイルに書いていたので、書き直してrake db:migrate:resetで書き換えました

t.string :nickname,           null: false
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""
      t.string :last_name,          null: false
      t.string :first_name,         null: false
      t.string :last_name_kana,     null: false
      t.string :first_name_kana,    null: false
      t.date :birthday,             null: false
      t.integer :tel,               null: false, unique: true
      t.string :avatar

これでできました:hugging:

####電話番号はintegerだとダメで、stringはOKだそうです。

勉強になりました:innocent:

12
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?