如何从Carrierwave Uploader对象引用父模型 [英] How to reference parent model from Carrierwave Uploader object

查看:104
本文介绍了如何从Carrierwave Uploader对象引用父模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Carrierwave完成文件上传后运行一些方法。 Carrierwave包括多个回调方法,详细的此处



我打算使用:store回调。

这很好,但它需要我运行Uploader对象实例中的回调方法。这不是世界末日,但我想保留我父母模型的所有逻辑。



我的问题是:我应该如何从Uploader引用父模型?我在文档中没有看到任何明显的东西



我想我可以做一些像

  ParentModel.last.call_my_method_here 

但这看起来像是一个非常脆弱的方式来编码(不期待很多请求,但仍然)。

解决方案

我想 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_here

but 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对象引用父模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆