jeudi 12 novembre 2020

Issue with the build for has_one association

I get getting an error every time I try to save a model with a has_one association, and I am not sure what I am doing wrong. Here is the error message and code below enter image description here

user.rb

  has_one :user_options

user_option.rb

 belongs_to(
        :user,
        class_name: 'User',
        foreign_key: 'user_id',
        inverse_of: :user_options
    )

user_options_controller.rb

def create
    @user = current_user
    @user_option = current_user.build_user_option(user_option_params)
    respond_to do |format|
      if @user_option.save
        format.html { redirect_to @user_option, notice: 'User option was successfully created.' }
        format.json { render :show, status: :created, location: @user_option }
      else
        format.html { render :new }
        format.json { render json: @user_option.errors, status: :unprocessable_entity }
      end
    end
  end

Any help would be great!

Aucun commentaire:

Enregistrer un commentaire