Activeresource, updating and merging

2019-08-26 10:42发布

问题:

I've run into a problem I'm not able to handle right now with an ActiveResource object that looks something like this:

#<Settings:0x000000085fff48
 @attributes=
  {"account_id"=>1,
   "created_at"=>"2012-01-10T14:54:36Z",
   "id"=>1,
   "settings_hash"=>
    #<Settings::SettingsHash:0x000000085ff250
     @attributes=
      {"email_notices"=>
        #<Settings::SettingsHash::EmailNotices:0x0000000860c860
         @attributes=
          {"none"=>
            ["none", "none"]},
         @persisted=false,
         @prefix_options={}>,
       "permissions"=>
        #<Settings::SettingsHash::Permissions:0x0000000860c1d0
         @attributes=
          {"default"=> [["all"], ["all"] ]},
         @persisted=false,
         @prefix_options={}>},
     @persisted=false,
     @prefix_options={}>,
   "field_key"=>"BRp7Box33sg",
   "fieldone"=>1,
   "updated_at"=>"2012-01-10T14:54:36Z"},
 @persisted=true,
 @prefix_options={}>

Which us where it comes from an ActiveRecord model with field that is serialized as a hash. I feel as if I'm doing to much work to unpack that hash AND I can't seem to add to it and update the model. I mean I can add to it while toying with it but it takes something like:

thisobject.settings_hash['permissions'].attributes.merge({"derp"=>[['dsfasdf'],['asdfasdfadsf']]})

which I'm having difficulty gettng back into the object and then which I want to update back where it came from.

So, I'm doing something I don't quite have a grasp of right now, perhaps in an awkward way. Suggestions?

I want to add a hash to hash field within an ActiveResource object to update a ActiveRecord object instance elsewhere, but can't quite at the moment.