Alex Shelmire
Alex Shelmire

Reputation: 61

How do you move an ActiveStorage::Attached::One to an ActiveStorage::Attached::Many?

I have two fields on a model called Project:

has_one_attached :image
has_many_attached :assets

I want to move the image to the assets so I can get rid of the has_one_attached :image.

Upvotes: 2

Views: 300

Answers (1)

Alex Shelmire
Alex Shelmire

Reputation: 61

I answered my own question but thought it would be useful to share:

p = Project.find(id)
p.assets.attach(p.image.blob)
p.image.detach

This successfully removed the image and moved it to assets.

Upvotes: 2

Related Questions