Mano
Mano

Reputation: 987

How to copy images using amoeba gem in rails?

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

Upvotes: 3

Views: 1777

Answers (3)

Abdur Rafay
Abdur Rafay

Reputation: 123

customize(lambda { |original_object, new_object|
  new_object.picture.attach(original_object.picture.blob) if original_object.picture.attached?
})

This worked for me

Upvotes: 0

mohamed-ibrahim
mohamed-ibrahim

Reputation: 11137

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.

Upvotes: 5

Gagan Gami
Gagan Gami

Reputation: 10251

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

Upvotes: 1

Related Questions