GithubHelp home page GithubHelp logo

Comments (11)

fro avatar fro commented on September 3, 2024

It seems it's working... if you override the attribute:

def duplicate
  resource_dup = self.dup :include => :something
  resource_dup.pdf_file = self.pdf_file
  resource_dup.save!
end

from deep_cloneable.

moiristo avatar moiristo commented on September 3, 2024

Yes, I've done it like this in one of my projects as well. But I think I created this suggestion with the idea in mind that it should be possible to do this without overriding the dup.

from deep_cloneable.

moiristo avatar moiristo commented on September 3, 2024

I think the addition of cloning with a block is sufficient to support cloning file attachments, therefore I'm closing this ticket.

from deep_cloneable.

fro avatar fro commented on September 3, 2024

Well, it seems it's not working while cloning nested resources with attachments...

from deep_cloneable.

bcackerman avatar bcackerman commented on September 3, 2024

Agree with Fro, any fixes?

from deep_cloneable.

moiristo avatar moiristo commented on September 3, 2024
  • What attachment library are you using?
  • Do you have a code sample?

from deep_cloneable.

bcackerman avatar bcackerman commented on September 3, 2024

Hi, I'm using CarrierWave and my code looked like this: http://pastie.org/5556680

from deep_cloneable.

moiristo avatar moiristo commented on September 3, 2024

As the implementation for every attachment gem is different, I still don't think that this should be in this gem. My solution in this case would be to pass a block to the dup method to modify the copy. Below is an example. I haven't tried this before (the block option was added by someone else), so I can't guarantee it just works now. I'll add a test for it soon.

def self.duplicate_it(invoice)
  new_invoice = invoice.dup :include => {:lineitems => :images} do |original, kopy|
    kopy.image = original.image if kopy.is_a?(Image)
  end 

  new_invoice.save!
  return new_invoice
end

from deep_cloneable.

bcackerman avatar bcackerman commented on September 3, 2024

That worked!!!

from deep_cloneable.

bcackerman avatar bcackerman commented on September 3, 2024

Although this reuploads the file each time which just doesn't work for a lot of records...damn

from deep_cloneable.

moiristo avatar moiristo commented on September 3, 2024

I don't think that's something that can be solved easily.. I'd probably go for a solution in which you only copy the 'image' database attribute and perform the file copy in the uploads dir manually.

from deep_cloneable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.