I have one form that can create two models perfectly, but, is there any way to update one of the models and create the other?
Resuming:
I have a form for creating an appointment and also I can create the person for this appointment.
def new
@Cita = Cita.new
@Cita.build_paciente
render :new
end
def create
@Cita = Cita.new(params[:cita])
if @Cita.save
redirect_to :action => 'hoy'
else
render 'new'
end
This is working pretty well when I create the two models at time, but if I fill the person fields …
How can I do for UPDATING the person attributes (“paciente”) and creating the appointment (“Cita”) for that person.
Thanks.
Finally I solved it adding a hidden field filling the person_ID on the person form. When you send the ID in the model attributes rails makes an update instead of an insert for that model while creates the other model associating the nested model.
If this hidden field is empty, rails create the two models at time.