I am developing a simple action, when saving a register if there is value in a certain field the system must redirect to a create of another model / controller. I'm having trouble making this happen.
if @reproduction.update(reproduction_params)
if reproduction_params[:parturition].nil?
format.html { redirect_to reproductions_path, notice: I18n.t('crud.saved') }
format.json { render :show, status: :ok, location: @reproduction }
format.js { render 'reproduction', animal: @animal, reproductions: @reproductions }
else
@animal = Animal.new(@reproduction)
redirect_to new_animal_path
end
else
format.html { render :edit }
format.json { render json: @reproduction.errors, status: :unprocessable_entity }
format.js { render 'edit' }
end
end
The idea is that when saving the state of pregnancy, if there is childbirth after saving the user is directed to the registration of new animal. And if possible already selected in which gestation it was generated (this way we can trace the parents and other variables.