I'm having problems sending data to my database through the client_controller, the client model has the has_many relationship with client_address, when trying to submit the data, the following fields are registered (client, personal_documents and client_bank_information), but the client_addresses is not saved to the bank on the rails console apacere it was not allowed (Unpermitted parameter:: client_address_attributes), thanks for the help!
model:
class Client < ApplicationRecord
has_one :client_bank_information, :dependent => :destroy
has_one :personal_document, dependent: :destroy
has_many :client_addresses, :dependent => :destroy
accepts_nested_attributes_for :client_bank_information, allow_destroy: true
accepts_nested_attributes_for :personal_document, allow_destroy: true
accepts_nested_attributes_for :client_addresses, allow_destroy: true
end
controller:
class ClientsController < ApplicationController
include ErrorSerializer
# POST /clients
def create
@client = Client.new(client_params)
if @client.save
render json: @client, status: :created, location: @client
else
render json: ErrorSerializer.serialize(@client.errors)
end
end
private
def client_params
params.permit(
:name,
:email,
:phone,
:cpf_cnpj,
:accept,
:version_term_accept,
:birth_date,
personal_document_attributes: [:rg_front,
:rg_verse,
:cpf,
:cnh_front,
:cnh_verse,
:bank_card_front,
:proof_residence,
:profile_photo
],
client_bank_information_attributes: [:bank,
:account_type,
:agency,
:account_number
],
client_address_attributes: [
:spot_to_clean,
:zip_code,
:street,
:street_number,
:complement,
:district,
:city,
:state
]
)
end
end
Aucun commentaire:
Enregistrer un commentaire