问题描述
我想通过Carrierwave完成文件上传后运行一些方法。 Carrierwave包括多个回调方法,详细的。
我打算使用:store回调。
这很好,但它需要我运行Uploader对象实例中的回调方法。这不是世界末日,但我想保留我父母模型的所有逻辑。
我的问题是:我应该如何从Uploader引用父模型?我在文档中没有看到任何明显的东西
我想我可以做一些像
我想 model 变量就是你要找的,查看使用它的示例
I want to run some methods after the upload of a file has been completed via Carrierwave. Carrierwave includes several callback methods detailed here.
I'm planning on using the :store callback.
That's great, but it requires me to run the callback method in the Uploader object instance. This isn't the end of the world, but I want to keep all the logic inside of my parent Model.
My question is: How should I be referencing the parent model from the Uploader? I don't see anything obvious in the documentation?
I suppose I could do something like
ParentModel.last.call_my_method_herebut this seems like a very brittle way to code this (not expecting a lot of requests, but still).
解决方案I guess the model variable is what you were looking for, see examples using it here
这篇关于如何从Carrierwave Uploader对象引用父模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!