0

I'm trying to duplicate my record and using the amoeba gem. Everything copies fine except for the image (which is uploader via carrierwave)

For the image I tried doing a customized setting in amoeba like this:

amoeba do
    customize(lamba { |original_object, new_object|
        new_object.photo = original_object.photo
    })

but that just returned the path of the image still which when loading is looking in the individual record id.

Edit: ok so I install the copy_carrierwave_file gem and tried to implement it but it doesnt seem to work. I am calling this function in the after_save callback

def create_duplicate
        puts 'Starting duplication'
        new_recipe = self.amoeba_dup
        new_recipe.original_id = self.id

        CopyCarrierwaveFile::CopyFileService.new(self, new_recipe, :photo).set_file
        new_recipe.save
end

I dont get any errors in the server or anywhere but it doesnt do anything

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
DRing
  • 6,825
  • 6
  • 29
  • 45

1 Answers1

0

You can copy file manually:

new_object.photo = File.open(original_object.photo.file.file) if original_object.photo.present?

Another way to upload file from local file is described here.

You can look at copy_carrierwave_file gem too.

Sergey Sokolov
  • 994
  • 7
  • 6
  • I tried the gem but it still isnt working, see the edit please – DRing Jul 31 '16 at 17:46
  • Looks like it should work.. Did you try other options? (new_object.photo = File.open(original_object.photo.file.file) or new_object.photo = Rails.root.join("path/to/image.png").open ) – Sergey Sokolov Jul 31 '16 at 19:31
  • I did, I tried as many combinations of what you put as I could. It has the path saved in the database...however it doesnt upload it to the new recipe folder in the app, so when it tries to load there is no folder for the id of the new recipe – DRing Jul 31 '16 at 19:57
  • May be new_recipe.remote_photo_url = photo_url_of_original_object and save after it can help. – Sergey Sokolov Jul 31 '16 at 20:40