ruby copy a paperclip attachment from one model to another?

两盒软妹~` 提交于 2019-11-30 17:14:19

This should do the trick, you could use an after_create callback if the models are associated, if not I would recommend doing it in the controller action that creates the card.

instance_of_model_one.cardimage = instance_of_model_two.avatar
instance_of_model_one.save
old_avatar = model1.avatar;
model2.avatar.create(attachment: old_avatar.attachment);
model2.save;

It worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!