お世話になっております。
現在ウィザード形式で新規登録のサーバーサイドの実装をしております。
問題なく遷移し、完了ページまで行けるのですが、情報がなにも保存されません。
binding.pryをすると、入力された値は取得できます。
知識不足で初歩的なミスかもしれませんが、お力を貸していただければと思います。
user.rb (バリデーションはまだ途中です)
class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable validates :nickname, presence: true, length: {maximum: 20} validates :email, presence: true validates :password, presence: true, length: {minimum: 7} validates :password_confirmation, presence: true, length: {minimum: 7} validates :family_name, :first_name, presence: true validates :family_name_kana, :first_name_kana, presence: true validates :birth_year, :birth_month, :birth_day, presence: true has_one :shipping_info, dependent: :destroy end
shipping_info (バリデーションはまだ途中です)
class ShippingInfo < ApplicationRecord belongs_to :user, optional: true validates :family_name, :first_name, :postcode, :prefecture, :city, :house_number, presence: true validates :family_name_kana, :first_name_kana, presence: true end
registration_controller.rb
# frozen_string_literal: true class Users::RegistrationsController < Devise::RegistrationsController # before_action :configure_sign_up_params, only: [:create] # before_action :configure_account_update_params, only: [:update] # GET /resource/sign_up # def new # super # end # POST /resource def new @user = User.new end def create @user = User.new(sign_up_params) unless @user.valid? flash.now[:alert] = @user.errors.full_messages render :new and return end session["devise.regist_data"] = {user: @user.attributes} session["devise.regist_data"][:user]["password"] = params[:user][:password] @address = @user.build_shipping_info render :new_address end def create_address @user = User.new(session["devise.regist_data"]["user"]) @address = ShippingInfo.new(shipping_info_params) unless @address.valid? flash.now[:alert] = @address.errors.full_messages render :new_address and return end @user.build_shipping_info(@address.attributes) @user.save session["devise.regist_data"]["user"].clear sign_in(:user, @user) end # GET /resource/edit # def edit # super # end # PUT /resource # def update # super # end # DELETE /resource # def destroy # super # end # GET /resource/cancel # Forces the session data which is usually expired after sign # in to be expired now. This is useful if the user wants to # cancel oauth signing in/up in the middle of the process, # removing all OAuth session data. # def cancel # super # end # protected # If you have extra params to permit, append them to the sanitizer. # def configure_sign_up_params # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) # end # If you have extra params to permit, append them to the sanitizer. # def configure_account_update_params # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) # end # The path used after sign up. # def after_sign_up_path_for(resource) # super(resource) # end # The path used after sign up for inactive accounts. # def after_inactive_sign_up_path_for(resource) # super(resource) # end protected def shipping_info_params params.require(:shipping_info).permit(:family_name, :first_name, :family_name_kana, :first_name_kana, :postcode, :prefecture, :city, :house_number, :building, :home_call_num) end end
よろしくお願い致します。
あなたの回答
tips
プレビュー