Copy image from one model to another

0

I have a question I am currently using carrierwave and google storage to store images, but I wanted to know if there is a way to take the image of the model to and assign it to another model so that it stores that same image.

currently try this but without results:

modelo1 = Modelo1.last

modelo2.picture_name = modelo1.file_name
modelo2.picture_content_type = modelo1.file_content_type
modelo2.picture_size = modelo1.file_size
modelo2.picture_updated_at = modelo1.file_updated_at
modelo2.original_picture_name = modelo1.original_file_name

modelo2.save
    
asked by mariovzc 26.09.2018 в 21:44
source

2 answers

0

Well the problem was at the database level, I gave deadlock to the general copy by a process independent of the app.

    
answered by 29.10.2018 / 22:23
source
0

You could use the dup method to assign all the attributes of model1 to model2 and then overwrite those you need to change in model2

your code would be something like this:

modelo1 = Modelo1.last
modelo2 = modelo1.dup
# si requieres cambiar algo del modelo2 puedes hacerlo aqui y despues guardas
modelo2.save
    
answered by 27.10.2018 в 01:48