3

I am using amoeba gem for duplicating record and i am using carrierwave for uploading images.

I tried to copy the images from the associated model using amoeba, it only copies the data from the original record(it copies only icon name,file attributes in the database), but the images are not present in filesystem (in Public folder)

This is my model

class Book < ActiveRecord::Base
  has_many :images
  self.class.amoeba do
    include_field [:images]
  end
end

class Image < ActiveRecord::Base
  belongs_to :book
end

I used the following method

duplicate = @book.amoeba_dup
duplicate.save

I tried with the following in Book model

amoeba do
    include_field :images
end

Help me to solve this

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
Mano
  • 979
  • 1
  • 18
  • 36

3 Answers3

4

You can add the following to image model:

  amoeba do
     customize(lambda { |original_object,new_object|
       new_object.image = original_object.image
     })
  end

OR if you even has the attachment in same model you can use same code in the model itself, the idea behind is you need to assign the paperclip object itself and without this part it only copy paperclip fileds for file name, file size and file type withour copy the attachment file itself.

mohamed-ibrahim
  • 10,837
  • 4
  • 39
  • 51
1

I haven't any experience with this gem but Have you tried by adding below code to the Book model

amoeba do
    enable
  end

for more details refer this documentation this may help you

Gagan Gami
  • 10,121
  • 1
  • 29
  • 55
0
customize(lambda { |original_object, new_object|
  new_object.picture.attach(original_object.picture.blob) if original_object.picture.attached?
})

This worked for me

Abdur Rafay
  • 73
  • 1
  • 6