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

486
Views
Cocoon data-association-insertion-node with a function

According https://github.com/nathanvda/cocoon#link_to_add_association you should be able to pass a function to data-association-insertion-node

I have tried this:

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

And this:

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

And this (getting desperate):

<%= 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;}'} %>

But none of them work.

Javascript:

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

I am trying to add a tr to a table and then append the nested timeslot form to the tr.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

At the moment this is not possible what you are trying to do. When setting the data-association-insertion-method like this, it will just be a string in javascript, and not a reference to a method.

As documented in the README, you have to do the following (assuming you gave your links a class .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')
    });
});

(the example is almost verbatim copied from documention for demonstration purposes only --you will have to fill in your get_row function)

about 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!