title: How to submit an array of integers in a Rails form?
body: <p>I would like to know if there is a way to have some sort of input field in a Rails form, so that if the user enters <code>1, 2, 3</code>, then <code>params[:model][:attribute]</code> returns <code>[1, 2, 3]</code> or at least <code>['1', '2', '3']</code>, but not <code>['1, 2, 3']</code>.</p>
  
  <p>Background:</p>
  
  <p>I have a model <code>Foo</code>, which has an attribute <code>bar_ids</code>. The datatype of this attribute in the PostgresQL database is <a href="http://www.postgresql.org/docs/9.3/static/arrays.html" rel="nofollow">Array</a>. I've tried several things:</p>
  
  <ul>
  <li>if <code>f.text_field :bar_ids</code> then <code>params[:foo][:bar_ids]</code> returns <code>'1, 2, 3'</code></li>
  <li>if <code>f.text_field_tag 'foo[bar_ids][]'</code> then <code>params[:foo][:bar_ids]</code> returns <code>['1, 2, 3']</code></li>
  <li>if <code>f.number_field :bar_ids</code> then <code>params[:foo][:bar_ids]</code> returns <code>'1'</code> if I input only <code>1</code> and the form does not allow to input multiple numbers</li>
  </ul>
  
  <p>So, again my question - is there a way to construct my form in such a way, so that Rails automatically parses the input to the respective datatype, in my case - an array of integers?</p>