CarrierWave:多种型号的单上传器? [英] CarrierWave: Single uploader for multiple models?

查看:177
本文介绍了CarrierWave:多种型号的单上传器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让单张图片上传器根据创建图片的型号执行不同的操作?

How do I make the single image uploader do different actions depending on the model it is creating the image for?

我有一个图片上传器,我想要上传用户和帖子的图片。对于用户,我想要原始图像&缩略图(70x70)。对于帖子,我想要原始图像和精选缩略图(260x180)。我可以为每个图像制作3个版本,只需调用所需的版本,但这可能非常糟糕,因为它会阻塞我的存储数据库。

I have one image uploader, and I want to upload images for Users and for Posts. For the user, I want the original image & thumbnail (70x70). For the Posts, I want the original image and featured thumbnail (260x180). I could just make 3 versions for every image and just call the desired one, but that's probably really bad since it would clog my storage database.

我看了:
Carrierwave;多个上传者或只有一个?
看起来可能的解决方案是创建子类。但是,我不太确定如何做到这一点 - 我尝试按照建议做出来但没有成功。

I looked at: Carrierwave; multiple uploaders or just one? and it looks like a possible solution is to create subclasses. However, I wasn't too sure how I would do this - I tried doing it as the answer suggested but with no success.

推荐答案

您应该使用单独的载波上传器,因为行为不同。这里不需要子类,除非你想在这两个上传者之间共享一些代码。

You should use separate carrierwave uploaders since the behaviors are different. There's no need of subclass here unless you want to share some codes between these two uploaders.

只需添加另一个上传者,除了<$之外,它应该与现有的上传者相同c $ c>版本 part。

Just add another uploader which should be the same of your existing one besides the version part.

这篇关于CarrierWave:多种型号的单上传器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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