1
5

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.

ユーザー新規登録備忘録 part2:新規登録時のdate_selectタグとsessionの組み合わせの使い方メモ

Last updated at Posted at 2019-10-30

sessionを用いてdate_selectで取得したデータをUserテーブルに情報を送る

某フリマアプリでユーザー登録の際に日付のデータの情報を送れなくてつまづいたので備忘録。

image01.png

date_select部分の情報だけはuser_paramsだと日付を持っていけない!?

スクリーンショット 2019-10-30 17.42.55.png

paramsだったら持ってこれた!!

スクリーンショット 2019-10-30 17.42.07.png

修正後

修正後
class SignupController < ApplicationController

  def names
    @user = User.new # 新規インスタンス作成
  end

  def telephones
    binding.pry//日付を取得できるか確認する
    # namesで入力された値をsessionに保存
    session[:nick_name] = user_params[:nick_name]
    session[:email] = user_params[:email]
    session[:password] = user_params[:password]
              [省略]
    session["birthday(1i)"] = params[:birthday]["birthday(1i)"] //user_paramsではなくparamsを使う
    session["birthday(2i)"] = params[:birthday]["birthday(2i)"] //user_paramsではなくparamsを使う
    session["birthday(3i)"] = params[:birthday]["birthday(3i)"] //user_paramsではなくparamsを使う
    @user = User.new # 新規インスタンス作成
  end
  
  [省略]
  
    # 許可するキーを設定します
  def user_params
    params.require(:user).permit(
      :nick_name,
      :email,
      :password,
      [省略]
      :birthday,
      [省略]
    )
  end

解決方法

paramsで見つかった

#####参考

1
5
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
1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?