使用回形针和导轨调整数千张图像大小的最佳方法是什么?

时间:2012-09-12 15:59:18

标签: ruby-on-rails paperclip

我有一张带有6张回形针照片的照片(照片1,照片2,照片3,照片4,照片5和照片6)。

因为最近网站设计的变化我需要调整六张图片上的所有风格。风格小,中,大。

我的想法是使用before filter方法来做一个Model.photo1.reprocess!并向模型表添加一列(例如“rerocess”作为boolean)以检查它是否被重新处理。

我认为这个想法比使用rake脚本在下次部署的单次迁移中迁移所有照片更有效。

产品控制器

before_filter :check_image_reprocess, :only => [:show]  

def check_image_reprocess
  @product = Product.find(params[:id])
  if @product.reprocess == false
    @product.photo.reprocess! unless @product.photo.nil?
    @product.photo2.reprocess! unless @product.photo2.nil?
    @product.photo3.reprocess! unless @product.photo3.nil?
    @product.photo4.reprocess! unless @product.photo4.nil?
    @product.photo5.reprocess! unless @product.photo5.nil?
    @product.photo6.reprocess! unless @product.photo6.nil?
    @product.update_attributes(:reprocess => true)
  end
end

实际上它是有效的,但是如果对这个或更好的建议有任何评论,那么会非常欢迎:)?

提前致谢

1 个答案:

答案 0 :(得分:0)

这样,经过1周的测试,它就能完美运行!!

享受

相关问题