项目地址: https://github.com/jnicklas/carrierwave
gem 'carrierwave', "0.6.2" bundle install rails generate uploader Video
gem 'mini_magick', "3.3"
include CarrierWave::MiniMagick # Create different versions of your uploaded files: version :thumb do process resize_to_fill: [150, 150] end version :main do process resize_to_fill: [600, 400] end version :cif do process resize_to_fill: [320, 240] end
rails g scaffold video title:string file:string message_id:integer deleted:boolean user_id:intege
rake db:migrate
rails g bootstrap:themed Videos
mount_uploader :file, VideoUploader
u.avatar.url # => '/url/to/file.png' u.avatar.current_path # => 'path/to/file.png' u.avatar.identifier # => 'file.png'
<%= form_for @user, :html => {:multipart => true} do |f| %> <% end %>
def resize_to_limit(width, height) process :resize_to_limit => [width, height] end def resize_to_fit(width, height) process :resize_to_fit => [width, height] end def resize_to_fill(width, height, gravity='Center') process :resize_to_fill => [width, height, gravity] end def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity) process :resize_and_pad => [width, height, background, gravity] end