title: Trying to convert a String to Array before saving to database Rails
body: <p>So I'm trying to convert a string that I get from a hidden_field to an array before I save it to the database and I'm having no luck. My Active record datatype is:</p>
  
  <p><code>add_column :contractors, :regions, :text, array: true</code></p>
  
  <p>My model looks like this</p>
  
  <pre><code>class Contractor &lt; ActiveRecord::Base
    before_validation :make_array
  
  private
      def make_array
          self.regions = self.regions.split(',')
      end
  end
  </code></pre>
  
  <p>and I'm getting the value from a hidden field</p>
  
  <pre><code>&lt;%= f.hidden_field :regions, value: "1,2,3" %&gt;
  </code></pre>
  
  <p>It seems if I have <code>array: true</code> on database column <code>self.regions</code> is an empty array when the callback runs. If I remove <code>array:true</code> the string is converted to an array with the callback but it won't save to the database (can't cast Array to text). I've tried adding <code>serialize: :regions</code> but I get this error:</p>
  
  <pre><code>ERROR:  array value must start with "{" or dimension information.
  </code></pre>
  
  <p>I've also tried sending an array from the hidden field with no luck.</p>
  
  <p>Any ideas what I am doing wrong? </p>