Adding/editing manual metadata to an already attached/persisted file?

This area of the docs addressses my question:

(It’s possible i myself even contributed those docs years ago!)

I think what the docs describe used to be true (maybe in shrine 2), but I’m having trouble with it.

Using ActiveRecord integration, if I do:

photo.image_attacher.add_metadata("foo" => "bar")
photo.image.metadata #=> { ..., "foo" => "bar" } # persist changes


photo.image.metadata # does NOT include `"foo" => "bar"`

The save does not seem to actually save the new metadata. I think using image_attacher.add_metadata somehow doesn’t result in the column being recognized as changed and needing saving.

Does anyone have any ideas? Thanks!

I think I was doing photo.image.add_metadata instead of photo.image_attacher.add_metadata!

There is an add_metadata method on both, but you have to call it on the _attacher if you want it to persist succesfully!

I think I have it working now.