Comments (11)
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.
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.
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.
Well, it seems it's not working while cloning nested resources with attachments...
from deep_cloneable.
Agree with Fro, any fixes?
from deep_cloneable.
- What attachment library are you using?
- Do you have a code sample?
from deep_cloneable.
Hi, I'm using CarrierWave and my code looked like this: http://pastie.org/5556680
from deep_cloneable.
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.
That worked!!!
from deep_cloneable.
Although this reuploads the file each time which just doesn't work for a lot of records...damn
from deep_cloneable.
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)
- rails 4 deep_clone different in development/staging and production HOT 2
- deep_clone not called on has_many_through relation HOT 4
- How to handle :has_rich_text associations in rails 6 HOT 3
- include:do loop also modified the includes HOT 1
- How To Attach Polymorphic Associated Records To A Different Model? HOT 2
- Error: private method `open' called for #<ActiveStorage::Attached::Many HOT 20
- Options argument hash for deep_clone is modified HOT 2
- Question: How to deep clone classes associated to the same class, as in a linked list or tree? HOT 1
- Conditional nested includes HOT 2
- Include all associations without having to specify all of them? HOT 1
- 3.1.0 is not released to rubygems.org? HOT 2
- Using deep clone to extract a subset db from production HOT 2
- Possible unexpected has_and_belongs_to_many behaviour. HOT 2
- Add support for Rails 7
- deep_clone has issues with acts_as_tenant gem how we can make it work ? HOT 1
- Add support for Mongoid HOT 1
- How to handle multiple parents? HOT 1
- Not possible to exclude attribute named 'rank' HOT 2
- Fix documentation for Active Storage usage in Rails 6.1
- problem with counter_cache HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deep_cloneable.