CarrierWave: Single uploader for multiple models?

烈酒焚心 提交于 2019-12-23 23:25:11

问题


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

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.

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.


回答1:


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.

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



来源:https://stackoverflow.com/questions/10458324/carrierwave-single-uploader-for-multiple-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!