Paperclip
Manage Uploaded Files Without Hassle
Paperclip is a plugin for Ruby on Rails’ ActiveRecord that lets files work as simply as any other attributes do. There are no extra database tables, only one library to install for image processing, and the ease of being able to refer to your files as easily as you refer to your other attributes.
Quick links:
Getting it
The main repository is at:
git://github.com/thoughtbot/paperclip.git
There are tags corresponding to each released version, but the most recent state of the code is always in master. Gems will be reissued through github soon.
Usage
In your model:
class User < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :medium => "300x300>",
:thumb => "100x100>" }
end
In your edit and new views:
<% form_for :user, :html => { :multipart => true } do |form| %>
<%= form.file_field :avatar %>
<% end %>
In your controller:
def create
@user = User.create( params[:user] )
end
In your show view:
<%= image_tag @user.avatar.url %>
<%= image_tag @user.avatar.url(:medium) %>
<%= image_tag @user.avatar.url(:thumb) %>
Bugs and Features
Please use our Lighthouse account for reporting bugs. You can post to the Google Group if you want discuss a feature. Or you could use either for either; what’s important is that we hear from you.
Requirements
Only ImageMagick, which you can install quite easily install via apt, yum, or port, or the package manager of your choice.
Copyright and License
All code is © 2008, thoughtbot, inc. and is released under the MIT License.
Feel free to email us with any questions or feedback.