0

I'm using Rails 4 and Mongoid 4. In my app I have a model I have a hash attribute. I'm trying to update this attribute like so:

user = User.find(id)
user['hash_attr']['another_attr'] = another_hash
user.save

But the above code doesn't seem to get persisted in the database. If I print the object like so:

puts user['hash_attr']['another_attr']

I get the right result, so there's no error but I try to load the model again (after the update):

user = User.find(id)
puts user['hash_attr']['another_attr']

The attribute is not updated... I've seen this article but 1) is quite old so maybe there's something new on this area and 2) it didn't work for me.

Any suggestions?

WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95

1 Answers1

0

it should be user.hash_attr['another_attr'] user.save

tessie
  • 964
  • 3
  • 14
  • 24