Here's what I'm doing in Coffeescript:
good_docs = []
$('#documents_yes a').each (index) ->
good_docs.push parseInt($(@).data('id'))
$('.hidden-docs').val(good_docs) #this is a hidden field
The problem is that the array is passed to my rails app as ["1, 2, 3"], but I need it to go in as [1, 2, 3].
How can I do this? I thought the parseInt call would handle it.
parseIntis doing exactly what you think, but then you're storing an array in an HTML input field. This will stringify your data. I suggest using aselectinput with the multiple attribute, and tinker with that. Look at this question for a little inspiration: stackoverflow.com/questions/16582901/…<input type="hidden" name="whatever[]">to pass the array to Rails? That would give you an actually array insideparamsin Rails.good_docswill be variable. I thought it be easier to have one field to put them in rather than building a custom number of fields on the fly. Of course, it hasn't turned out to be easier.... :)<input type="hidden">as above and manipulate those, you'll get a more natural interface and everyone will be happier. You can attachclassattributes to the hidden inputs to make it easier to manipulate them or throw them all in container of some sort.