简体   繁体   English

如何使用变形虫宝石在铁轨中复制图像?

[英]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 我在Book模型中尝试了以下内容

amoeba do
    include_field :images
end

Help me to solve this 帮我解决这个问题

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. 或者如果你甚至在同一模型中有附件你可以在模型本身使用相同的代码,背后的想法是你需要自己分配回形针对象而没有这部分它只复制paperclip fileds文件名,文件大小和文件类型我们复制附件文件本身。

I haven't any experience with this gem but Have you tried by adding below code to the Book model 我对这个宝石没有任何经验,但您是否尝试将下面的代码添加到Book模型中

amoeba do
    enable
  end

for more details refer this documentation this may help you 有关详细信息,请参阅此文档,这可能对您有所帮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM