I have a model foo in my rails app, and in the index page all the foos are listed in a table. Each foo has 2 integer properties: quarto and jesolo.

I’m giving different ids to the html number fields, in the following way:
foo #1
1st field: foo1_quarto
2st field: foo1_jesolo
foo #2
1st field: foo2_quarto
2st field: foo2_jesolo
ecc…
At the moment I’m using the following ajax code (written in coffee script) to make the user input on foo1_quarto being reflected also in foo1_jesolo:
$("#foo1_quarto").keyup ->
a = parseInt document.getElementById("foo_quarto").value
$("#foo1_jesolo").val a
But now I need to serialize this. I don’t know in advance how many food there will be, and I’d like to have a piece of ajax code that covers all of them
Not sure I understand your english, but couldn’t you collect all the inputs and serialize them like so ?
So in an AJAX call it would be :
Also, I’d personally stray away from using unique ID’s for your
keyupmethod. In this way, you wouldn’t have to write the same thing for every single item.Instead I would make each one share a common class
.foo_inputand/or.other_foo, and write it like so :But ideally, you would use one class and use jQuery selectors to get to it. Not sure how your HTML is set up.