title: Ruby on Rails: Submitting an array in a form
body: <p>I have a model that has an attribute that is an Array. What's the proper way for me to populate that attribute from a form submission?</p>
  
  <p>I know having a form input with a field whose name includes brackets creates a hash from the input. Should I just be taking that and stepping through it in the controller to massage it into an array?</p>
  
  <p>Example to make it less abstract:</p>
  
  <pre><code>class Article
    serialize :links, Array
  end
  </code></pre>
  
  <p>The links variable takes the form of a an array of URLs, i.e. <code>[["http://www.google.com"], ["http://stackoverflow.com"]]</code></p>
  
  <p>When I use something like the following in my form, it creates a hash:</p>
  
  <pre><code>&lt;%= hidden_field_tag "article[links][#{url}]", :track, :value =&gt; nil %&gt;
  </code></pre>
  
  <p>The resultant hash looks like this: </p>
  
  <pre><code>"links" =&gt; {"http://www.google.com" =&gt; "", "http://stackoverflow.com" =&gt; ""}
  </code></pre>
  
  <p>If I don't include the url in the name of the link, additional values clobber each other:</p>
  
  <pre><code>&lt;%= hidden_field_tag "article[links]", :track, :value =&gt; url %&gt;
  </code></pre>
  
  <p>The result looks like this: <code>"links" =&gt; "http://stackoverflow.com"</code></p>