Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Carrierwave recreate version

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?

like image 902
user929062 Avatar asked Jan 12 '23 10:01

user929062


2 Answers

Image.all.each { |i| i.image.recreate_versions! }
like image 65
itsnikolay Avatar answered Jan 17 '23 22:01

itsnikolay


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

like image 38
Amar Avatar answered Jan 17 '23 23:01

Amar