Resize existing images to new style in paperclip & RMagick

前端 未结 2 1310
青春惊慌失措
青春惊慌失措 2021-01-29 20:00

I\'ve been using paperclip to upload and auto-resize photos in my Rails app, and I love it. Only problem is about every other month my crazy manager decides he wants a new size

2条回答
  •  一个人的身影
    2021-01-29 20:30

    You want the reprocess! method of Paperclip::Attachment. See the docs.

    class User < ActiveRecord::Base
      has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
    end
    
    # Console...
    >> User.find_each { |u| u.avatar.reprocess! }
    

    Also, according to the comments before the reprocess! method, there's a paperclip:refresh Rake task, which might be easier.

提交回复
热议问题