Wizard-style new membership does not save information to db

Asked 2 months ago, Updated 2 months ago, 5 views

Prerequisites/What you want to achieve

I would like to register my user information in db by registering as a new member of the wizard method.

We are currently creating a personal development application.
We are trying to achieve user registration using the wizard form using the device.
Page 1: Profile image, name, etc.
Page 2: Address (including automatic address entry
) Page 3: Completion Page

Before I created another model, I was able to register without any problems, but
After the creation and association implementation of other models, it is no longer saved in db.
(We also install carrierwave, so it's not clear where it's no longer possible.)

Problems/Error Messages you are experiencing

There were no specific error statements, so when I changed from save to save!, I received the following error statement:

Enter a description of the image here
Also, the console is ROLLBACK as shown below.

Enter a description of the image here

Source Codes Affected

Device controller for wizard-driven forms.


class Users::RegistrationsController <Device::RegistrationsController
  # before_action: configure_sign_up_params, only: [:create]
  # before_action: configure_account_update_params, only: [:update]

  def new

  def create
    [email protected] lid?
      flash.now [:alert] = @user.errors.full_messages
      render:new and return
    session["device.register_data"] = {user:@user.attributes}
    @[email protected]_address
    render —new_address
  def create_address

    [email protected] lid?
      flash.now [:alert] = @address.errors.full_messages
      render —new_address and return
  # GET/resource/edit
  # default
  #   super
  # end

  # PUT/resource
  # default update
  #   super
  # end

  # DELETE/resource
  # def destroy
  #   super
  # end

  # GET/resource/cancel
  # Forces the session data which is userally 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
  #   device_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
  #   device_parameter_sanitizer.permit(:account_update, keys:[:attribute])
  # end

  # The path used after sign up.
  # after_sign_up_path_for (resource)
  #   super(resource)
  # end

  # The path used after sign up for inactive accounts.
  # after_inactive_sign_up_path_for (resource)
  #   super(resource)
  # end

  default address_params


class ApplicationController<ActionController::Base
  protect_from_forgery with: —Exception
  before_action: configure_permitted_parameters, if: —device_controller?
  after_sign_in_path_for (resource)
  after_sign_out_path_for (resource)

  def configure_permitted_parameters
    device_parameter_sanitizer.permit(:sign_up, keys:[:nickname,:first_name,:last_name,:first_name,:first_name_kana,:last_name_kana,:birthday,:image])


class User<ApplicationRecord
  # Include default device modules.Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  device:database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  values:nickname, :first_name, :last_name, :first_name_kana, :last_name_kana, :birthday, :image,presence:true
  has_one —address
  has_many —posts
  has_many —messages
  include JpPrefecture
  mount_uploader: image, ImageUploader


  def perfect_name = (prefect_name)
    self.prefecture_code = JpPrefecture::Prefecture.find(name:prefecture_name).code



class Address <ApplicationRecord
  belongs_to:user, optional:true
  mount_uploader: image, ImageUploader


■ Model
·Is the association not correct?

Other models associated with the user model are address, post, group, and message.
I checked if the relationship between has_many(one) and Belong to is well described in each

·Nil for foreign key not allowed?
Belong_to followed by optional:true

·Is the image not correctly taken over to the second page (address registration)?
I don't know if it's correct, but add mount_uploader: image, ImageUploader to address.rb

■ Controller ·Is the image not saved because Validation failed: Image can't be blank?
Verify that the image is listed in the device_parameter_sanitizer of the application_controller

·Add に@address.user=current_user under @address=Address.new(address_params)
It was a question that was asked elsewhere, and it was an answer, so I also tried it.

This is my first time using stack overflow.
I would appreciate it if you could let me know if there is anything difficult to understand how to ask.
Thank you for your cooperation.

ruby-on-rails ruby database

2022-09-30 11:49

1 Answers

image has failed, so it appears that the image uploaded in carrierwave and not yet saved has not been successfully taken over via session.

Since image_cache is required as well as image_cache to handle images that are not saved across HTTP requests in carrierwave, shouldn't @user.image_cache also be saved in session? (I've only used image_cache to set hidden in validation error, and there was no immediate environment, so it may not be @user.image_cache.)

register_data is better than register_data although it is not directly related to the error.

2022-09-30 11:49

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.