1

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.

1 Answer 1

3

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.