顯示具有 gem 標籤的文章。 顯示所有文章
顯示具有 gem 標籤的文章。 顯示所有文章

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