1
votes

I'm trying to create an user register using two models User and profile, nested strong parameters in one controller. when I send parameter I get this error unknown attribute 'profiles_attributes' for User. and I can't create user neither profile :

class User < ActiveRecord::Base
 has_one :profile
 has_many :apartments
 has_many :session

 has_secure_password
 validates :email, presence: true, uniqueness: true
 validates :password, presence: true

 accepts_nested_attributes_for :profile
end


class Profile < ActiveRecord::Base
 belongs_to :user
 belongs_to :city
 has_many :profile_universities
 has_many :universities, through: :profile_universities
 has_many :profile_preferences
 has_many :preferences, through: :profile_preferences
 has_one :photo, :as => :imageable
end


class Api::V1::UserController < ApplicationController
  before_action :user_params 
  def create_without_facebook


    @user= User.new(user_params)
    if @user.save
        @profile = Profile.new(user_params[:profiles_attributes])

        render json:  [@user, @profile]
    else
        render json: @user.errors, status: :unprocessable_entity

    end
  end

  def user_params
    params.require(:user).permit(:email, :password, profiles_attributes: [:first_name, :last_name, :birthday, :gender, :marital_status, :ocupation, :budget, :question, :about, :city])
  end

end
1

1 Answers

0
votes

use the singular profile_attributes if it's a has_one