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.

Getting it

The main repository is at

git://github.com/thoughtbot/paperclip.git

The SVN mirror is

https://svn.thoughtbot.com/plugins/paperclip/trunk/

There is a gem version available on RubyForge at

http://rubyforge.org/projects/paperclip/

Releases are tagged on both git and svn, and gems are made from tagged releases. The svn history is not as detailed as the git history, so if you need to see specific revisions, check the git logs (which you can do on github, if you’re using svn).

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.

More?

You may want to check out the Paperclip rdocs

Copyright and License

Paperclip is © 2008, thoughtbot, inc. and is released under the MIT License.