1

I have a User model and a Post model. A user's photo will be resized to a small thumbnail, and a post's photo will be resized to a large thumbnail.

version :smallThumb do
     process :resize_to_fill => [100, 100]
   end

   version :largeThumb do
     process :resize_to_fill => [200, 200]
   end

How do I tell carrierwave which size to choose for an uploaded photo? Will it resize to both small and large for all uploads?

4

1 回答 1

3

You can create 2 separate uploader models. Would look something like this:

profile_uploader.rb

class ProfileUploader < CarrierWave::Uploader::Base

  include CarrierWave::RMagick

  storage :file

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

end

atached_uploader.rb

class AttachedUploader < CarrierWave::Uploader::Base

  include CarrierWave::RMagick

  storage :file

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

end

user.rb

class User < ActiveRecord::Base

  mount_uploader :profile, ProfileUploader

end

post.rb

class Post < ActiveRecord::Base

  mount_uploader :attached, AttachedUploader

end
于 2011-06-09T09:24:59.213 回答