Rails return JSON serialized attribute with_indifferent_access

前端 未结 4 1485
日久生厌
日久生厌 2021-02-07 05:55

I previously had:

serialize :params, JSON

But this would return the JSON and convert hash key symbols to strings. I want to reference the hash

4条回答
  •  春和景丽
    2021-02-07 06:36

    use the built-in serialize method :

    class Whatever < ActiveRecord::Base
     serialize :params, HashWithIndifferentAccess
    end
    

    see ActiveRecord::Base docs on serialization for more info.

提交回复
热议问题