2014年6月15日 星期日

CarrierWave & rmagick


CarrierWave provides a generator called uploader to do this to which we pass the name we want to give our uploader, in this case image.
$ rails generate uploader Avatar
加欄位
$ rails g migration add_avatar_to_users avatar:string
Open your model file and mount the uploader
class User < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader
end

resize

class MyUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  process :resize_to_fit => [800, 800]

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

沒有留言:

張貼留言