Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

496
Views
Cocoon datos-asociación-inserción-nodo con una función

De acuerdo con https://github.com/nathanvda/cocoon#link_to_add_association , debería poder pasar una función a data-association-insertion-node

He intentado esto:

 <%= link_to_add_association 'Add Timeslot', f, :timeslots, :data => {'association-insertion-node' => 'get_row()'} %>

Y esto:

 <%= link_to_add_association 'Add Timeslot', f, :timeslots, :data => {'association-insertion-node' => 'get_row'} %>

Y esto (desesperándose):

 <%= link_to_add_association 'Add Timeslot', f, :timeslots, :data => {'association-insertion-node' => 'function get_row(node){var row = "<tr></tr>";$("#table_body").append(row);return row;}'} %>

Pero ninguno de ellos funciona.

JavaScript:

 function get_row(node){ var row = "<tr></tr>" $("#table_body").append(row); return row }

Estoy tratando de agregar un tr a una table y luego agregar el formulario de intervalo de tiempo anidado al tr .

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Por el momento esto no es posible lo que está tratando de hacer. Al configurar el data-association-insertion-method esta manera, solo será una cadena en javascript, y no una referencia a un método.

Como se documenta en el LÉAME, debe hacer lo siguiente (suponiendo que le dio a sus enlaces una clase .add-timeslot ):

 $(document).on('turbolinks:load', function() { $(".add-timeslot a"). data("association-insertion-method", 'append'). data("association-insertion-node", function(link){ return link.closest('.row').next('.row').find('.sub_tasks_form') }); });

(el ejemplo se copia casi literalmente de la documentación solo con fines de demostración; deberá completar su función get_row )

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!