How to reference a parent model from an Uploader Carrierwave object

I want to run some methods after the file download has completed through Carrierwave. Carrierwave includes several callback methods here .

I plan to use the callback: store.

This is great, but I need to run the callback method on an instance of the Uploader object. This is not the end of the world, but I want to keep all the logic inside my parent model.

My question is: how should I refer to the parent model from Uploader? I do not see anything obvious in the documentation?

I suppose I could do something like

ParentModel.last.call_my_method_here 

but it seems like a very fragile way to code it (not expecting a lot of requests, but still).

+4
source share
2 answers

I assume the model variable is what you were looking for, see examples using here

+8
source

For what it's worth, I used the after_commit for the parent model, which so far works correctly. It also allows me to interact with the downloaded file.

+1
source

Source: https://habr.com/ru/post/1441954/


All Articles