There are two ways to deal with this, and it will depend on your client architecture, how you do it, since HTTP standards do not make the situation cut and dry.
Traditionally, HTTP requests simply use the same key for duplicate values ββand leave it to the client architecture to understand what is happening. For example, you might have a mail request with the following values:
student_name=Bob+Smith&student_name=Jane+Smith&student_name=Chris+Smith
When the receiving architecture received this string, it would have to understand that there are several student_name keys and act accordingly. It is usually implemented so that if you have one key, a scalar value is created, and if you have a multiplicity of the same key, the values ββare placed in an array.
Modern client-side architectures such as PHP and Rails use a different syntax. Any key that you want to read as an array is added in square brackets, for example:
student_name[]=Bob+Smith&student_name[]=Jane+Smith&student_name[]=Chris+Smith
The receiving architecture will create an array structure named hostname without parentheses. The square bracket syntax solves the problem of the inability to send an array with only one value, which cannot be processed using the "traditional" method.
Since you are using Rails, square bracket syntax is the way to go. If you think you can switch server architectures or want to distribute your code, you can explore more agnostic methods, such as JSON encoding of the sent string, which adds overhead, but it can be useful if this is a situation that you expect to have to handle.
There is a great post in the context of jQuery Ajax Options here .
zombat
source share