سؤال

I'm using carrierwave and rmagick to handle my image uploads. I now added a new version (smallthumb) to my image_uploader.eb:

class ImageUploader < CarrierWave::Uploader::Base

  include CarrierWave::RMagick
  storage :file

  def store_dir
    "uploads/images"
  end

  version :thumb do
    process :resize_to_fill => [250, 250]
  end

  version :smallthumb do
    process :resize_to_fill => [70, 70]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end
end

I have a model called "image" with the image uploader mounted:

class Image < ActiveRecord::Base
  attr_accessible :date, :description, :name, :size, :image, :article_ids
  has_and_belongs_to_many :articles
  mount_uploader :image, ImageUploader
end

I have read that I need to call recreate_versions!, but I do not understand where I need to call this operation and how. I have my images on the live server in public/uploads/images. How can I recreate the versions of all these images (on my development machine and the live server) so that I have the smallthumb version of the image too?

هل كانت مفيدة؟

المحلول 2

Suppose user model has an image uploader.

then try this

user.all.each {|x|x.image.recreate_versions!}

OR

User.all.each do |user| user.avatar.recreate_versions! end

نصائح أخرى

Image.all.each { |i| i.image.recreate_versions! }

from https://github.com/carrierwaveuploader/carrierwave#recreating-versions

Image.find_each do |image|
  image.image.recreate_versions! if image.image?
end
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top