ruby copy a paperclip attachment from one model to another?

前端 未结 4 1336
Happy的楠姐
Happy的楠姐 2021-01-03 22:30

I have two models like this:-

Model 1 - card - contains a representation of data of interest for front page
attachment name = cardimage
Model 2 - user - c

4条回答
  •  再見小時候
    2021-01-03 23:14

    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
    

提交回复
热议问题