I have a model with an attribute of type date_array. The database is postgresql. When updating the model with the value of the attribute being an array of correctly formatted date strings, I get this error:
ActiveRecord::ArrayTypeMismatch (shipdates must be an Array or have a valid array value (''{"2014-01-16","2014-01-17","2014-01-18","2014-01-21"}'')):
app/controllers/vendor/orders_controller.rb:59:in `update'
Rendered /Users/sony/.rvm/gems/ruby-1.9.3-p448@ci-web/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.erb (3.0ms)
Rendered /Users/sony/.rvm/gems/ruby-1.9.3-p448@ci-web/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.3ms)
Rendered /Users/sony/.rvm/gems/ruby-1.9.3-p448@ci-web/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (32.0ms)
Postgres expects date_arrays to be a string like this: {"2014-01-16","2014-01-17","2014-01-18","2014-01-21"}
From the error message it appears that the value is getting enclosed in extra quotation marks. Not sure why.
Turns out the issue is a bug in one of the gems I was using. The gem is called activerecord-postgres-array and the latest bundle install
must have pulled in this bug: https://github.com/tlconnor/activerecord-postgres-array/issues/37
I have updated my gemfile to use version 0.0.8 of this gem. The update works fine now.
Gemfile:
gem 'activerecord-postgres-array', '0.0.8'