i have a hidden_tag like this in my form
<%= f.hidden_field :loc , {:multiple => true} %>
which renders to
<input id="business_loc" multiple="multiple" name="business[loc][]" type="hidden" style="color: rgb(175, 175, 175); " value="">
currently am setting the business_loc value as a comma seperated string hoping rails would recognize when submit the form. But this is the value i got on the server side
"loc"=>["80.22167450000006,13.0454044"]
instead
"loc"=>[80.22167450000006,13.0454044]
how do i set the correct value in hidden field, so rails can understand it correctly.
I had this same problem recently. My solution was to handle it on the server side by simply splitting the array at the comma. In my case it looks like this:
I've found text_area's to make things work without having to add a bunch of hidden forms. Just set the value of the text area to something that looks like
[1,31,51,61]
and it should work, assuming in your model you haveserialize :var
You need to use multiple hidden fields, one for each element of the array of values.
For example:
...if you need code to dynamically add these with JS, here's a jQuery example: