2014-01-28 47 views
1

我有一個模型的屬性類型爲date_array。數據庫是postgresql。當更新使用屬性被正確格式化的日期字符串數組值的模型,我得到這個錯誤:ActiveRecord :: ArrayTypeMismatch必須是一個數組或有一個有效的數組值

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/[email protected]/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.erb (3.0ms) 
    Rendered /Users/sony/.rvm/gems/[email protected]/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.3ms) 
    Rendered /Users/sony/.rvm/gems/[email protected]/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (32.0ms) 

Postgres需要date_arrays是這樣的字符串:{「2014年1月16日」, 「2014-01-17」,「2014-01-18」,「2014-01-21」}

從錯誤消息中可以看出,該值被加上了多餘的引號。不知道爲什麼。

回答

3

原來,這個問題是我使用的其中一個寶石中的一個錯誤。該寶石被稱爲activerecord-postgres陣列和最新的bundle install必須在這個bug中拉動:https://github.com/tlconnor/activerecord-postgres-array/issues/37

我已經更新了我的gemfile使用該寶石版本0.0.8。更新現在正常工作。

的Gemfile:

gem 'activerecord-postgres-array', '0.0.8' 
相關問題