-1
I’m developing a APP
in Rails
, and I came up with the following question regarding the class Person.
The structure of these classes are like this:
Pessoa { tipo, status }
PessoaJuridica { razãoSocial, nomeFantasia, CNPJ, IE, IM }
PessoaFisica { nome, apelido, CPF, RG }
In my view
of Person in _form.html.erb
I have a radio_button
to select the type of person to be registered(Fisica ou Juridica
), but I am in doubt how to create the form fields. In this case the relationship is has_one
from Pessoa to PessoaFisica/Juridica
, how I would create this _form to have the fields both from the table of PessoaFisica
as of PessoaJuridica
and change them depending on the selection of radio_button
?
I thought of creating two _forms
one for the individual, and the other for the legal and view
with a style display: none
; and show them with jQuery
when selected on radio_button
, that is valid ? And how would the controller
When saving the registration, how will I identify when creating, if you are a legal person ? and in which Model save ?
Thanks in advance, Hugs.
EDIT
I managed to create the _form
with all fields showing only the fields that the user selects with the radio_button
. The problem now is to save the register, as in practice I have the fields of two Model in _form
just 'hiding'(.Hide()) fields that are not from the selection of radio_button
, when I confirm the record, you’re saving a pessoa_juridica
and a pessoa_fisica
, and the one that was not selected in radio_button
keeps all fields blank (""). How do I resolve this ?