Skip to content

Instantly share code, notes, and snippets.

@aristotelesbr
Created July 23, 2017 04:48
Show Gist options
  • Save aristotelesbr/c8acaa1ce93eb07534548f6673487977 to your computer and use it in GitHub Desktop.
Save aristotelesbr/c8acaa1ce93eb07534548f6673487977 to your computer and use it in GitHub Desktop.
Exemplo nestend_attributes com rails
$("#tipo_doc").change(function() {
let id = this.value;
$("#campos").html(" ")
$.ajax({
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
url: '/protocolos/campos',
type: 'POST',
dataType: 'json',
data: { "tipo_documento" : id },
success: function(response) {
response.forEach(function(element) {
let numeroRand = 1000 + Math.floor(Math.random() * 10000);
$("#campos").append('<p><label>' + element + '</label></p><input type="text" name="protocolo[protocolo_campos_attributes]['+numeroRand+'][tipo]" id="'+element+'" />')
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment