问题
I know you can add new styles to paper clip and then use process! method to force paperclip to fill in the missing styles. But what if you want to ditch the old styles that you are not using any more.
For example I have styles iphone and ipad, and I changed my mind and would instead like :large and :medium with slightly different dimensions instead of :iphone and :ipad.
In particular I'm hosting my images on s3 since my app is on heroku. I would like to remove all the folders on s3 pertaining to :iphone and :ipad styles. Is there a rake task for removing select styles?
回答1:
If you are referring to removing invalid files, try:
rake paperclip:clean # Cleans out invalid attachments.
You can view all paperclip tasks in your console by typing:
rake -T paperclip
回答2:
run in your terminal
rake -T paperclip
you can see like this
...
rake paperclip:clean # Cleans out invalid attachments.
rake paperclip:refresh # Refreshes both metadata and thumbnails.
rake paperclip:refresh:metadata # Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT).
rake paperclip:refresh:missing_styles # Regenerates missing thumbnail styles for all classes using Paperclip.
rake paperclip:refresh:thumbnails # Regenerates thumbnails for a given CLASS (and optional ATTACHMENT and STYLES splitted by comma).
...
for refreshing your thumbnail try this
rake paperclip:refresh:thumbnails class= Xyz # xyz replace with your class name
for removing
rake paperclip:clean # Cleans out invalid attachments.
回答3:
You can use the Attachment#clear
method.
If you wanted to delete the thumb
and display
styles, you could run something like:
YourModel.find_each do |ym|
ym.attachment.clear(:display, :thumb)
ym.save!
end
回答4:
You will have to write a script to accomplish this, but paperclip does have a s3_object
convenience method that makes this easy:
obj = User.first.avatar.s3_object(:unwanted_style)
obj.delete if obj.exists?
You could place something like this within a loop for any objects you want to operate on.
Sources:
- Paperclip::Storage::S3 documentation
- aws-sdk Object documentaion
来源:https://stackoverflow.com/questions/12702078/how-to-remove-existing-style-dimensions-in-paperclip