Unable to serialize as ActiveSupport::HashWithIndifferentAccess anymore

前端 未结 4 1565
無奈伤痛
無奈伤痛 2021-01-18 16:46

For reasons that I\'m so far completely unable to decipher, I\'m no longer able to use ActiveSupport::HashWithIndifferentAccess anymore.

The relevant part of model l

4条回答
  •  星月不相逢
    2021-01-18 17:34

    Just in case anyone has the same problem I've been having, which is similar to this but not the same, I'm posting the answer here. I have a hash which is serialized in the model, which is saving correctly to the db. In one interface I need to regenerate the hash in JS, which would then create entries in the db containing !map:ActiveSupport::HashWithIndifferentAccess rather than the correct data. I am generating the hash as a string and then converting to a hash using eval. This created a Hash, as required. But I was then putting the hash back into the params hash, so I could use update_attributes in the controller which was converting it to HashwithIndifferentAccess, causing the problem

提交回复
热议问题