Unable to serialize as ActiveSupport::HashWithIndifferentAccess anymore

前端 未结 4 1512
無奈伤痛
無奈伤痛 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:11

    If you can, switch over to syck.

    In application.rb:

    require 'yaml'
    YAML::ENGINE.yamler = 'syck'
    
    0 讨论(0)
  • 2021-01-18 17:26

    1.9.2 normally includes Psych as the YAML library. However, libyaml is an external dependency, and 1.9.2 defaults to using Syck (the old library) if libyaml is not available when Ruby is compiled: link

    The fact that Psych YAML-izes ActiveSupport::HashWithIndifferentAccess as a standard hash is an oustanding issue on Psych's Github. Seems to be fixed in 1.9.3 though.

    0 讨论(0)
  • 2021-01-18 17:32

    Apparently this is just straight up broken with 1.9.2-p290.

    Upgrading to 1.9.3, or downgrading to 1.8.7 and everything's peachy. I'd love a better answer than that, though, if anyone has any ideas.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题