title: Rails, submitting array to postgres
body: <p>I have a Rails API and I am trying to pass an array of numbers to my postgres db but I can't: I send an array with two values, and it accepts an array with only the first value.</p>
  <p>I have 2 models, <code>Itinary</code> and <code>Event</code> where:</p>
  <pre><code>class Event 
    belongs_to: itinary
    accepts_nested_attributes_for :itinary
  
  class Itinary
     has_many: events
  </code></pre>
  <p>I use Postgres and a React front end and Rails API with Postgres. I declared a column of type <code>array</code> with values if type <code>decimal</code>:</p>
  <ul>
  <li>Rails Postgres schema: I set <code>DECIMAL</code> as the type:</li>
  </ul>
  <pre><code>create_table &quot;itinaries&quot;, force: :cascade do |t|
      ...
      t.decimal &quot;start_gps&quot;, default: [], array: true
  </code></pre>
  <ul>
  <li>Rails <code>EventsController</code>: nothing fancy, from the <code>Event</code> controller, the create method is: <code>Event.new(event_params)</code>, and the strong params method is also rather simple:</li>
  </ul>
  <pre><code>def event_params
     params.require(:event).permit( 
        ...,
        itinary_attributes: [...,  start_gps: [] ],
        ...
     )
  end
  </code></pre>
  <p>I checked that <code>Event.first.itinary.start_gps.class</code> returns <code>Array</code>. I can seed with <code>Itinary.create!(..., start_gps:[45,1])</code> (the values are numbers).</p>
  <ul>
  <li>React form: the data are sent within a <code>FormData</code> from React where I believe I used the correct Rails naming convention:</li>
  </ul>
  <pre><code>const fdata = new FormData()
  fdata.append(&quot;events[itinary_attributes][start]&quot;, itinary.start)
  fdata.append(&quot;events[itinary_attributes][start_gps][]&quot;, itinary.start_gps)
  ...
  </code></pre>
  <p>so the header of my POST request contains:</p>
  <pre><code>event[itinary_attributes][start_gps][]: 45.1936513315257,0.6646728515625
  </code></pre>
  <p>On submit, I get almost the desired params but the values in the array are quoted:</p>
  <pre><code> Parameters: 
  {&quot;event&quot;=&gt;{
     &quot;itinary_attributes&quot;=&gt;{
         &quot;date&quot;=&gt;&quot;2020-08-16&quot;,
         &quot;start&quot;=&gt;&quot;Paris FRA&quot;,
         &quot;start_gps&quot;=&gt;[&quot;48.85011347181819,2.3353889957070355&quot;], &lt;&lt; one value ?
         }
     }
  }
  </code></pre>
  <p>so that I get only the first value when Postgres fires:</p>
  <pre><code> Itinary Create (2.5ms)  
  INSERT INTO &quot;itinaries&quot; ...
    [&quot;start_gps&quot;, &quot;{48.85011347181819}&quot;], &lt;&lt;&lt;&lt;&lt; ONLY FIRST
                     ^^
  ]
  </code></pre>
  <ul>
  <li>If I set <code>t.string</code> or <code>t.text</code> as the data-type in the schema, Postgres fires:</li>
  </ul>
  <pre><code>Itinary Create (2.5ms) 
   [&quot;start_gps&quot;, &quot;{\&quot;45.18978009667531,0.6811523437500001\&quot;}&quot;]]
  </code></pre>
  <p>so <code>Event.last.itinary.start_gps.length</code> returns 1, a concatenated value:</p>
  <pre><code>start_gps: Array(1)
  =&gt; &quot;45.158800738352106,1.5051269531250002&quot;
  </code></pre>
  <p>I even tried to submit an array of strings from React without success. Where to start? This is something very classical I believe. Looks like Rails or Postgres can't read the comma ',' that separates two values in an array.</p>