public
Description: Easy file attachment management for ActiveRecord
Homepage: http://www.thoughtbot.com/projects/paperclip
Clone URL: git://github.com/thoughtbot/paperclip.git
jyurek (author)
Tue May 13 13:15:22 -0700 2008
commit  f1bf873f67646aef10c54c8ea0cc95d926beb7f6
tree    c63b98bf9e9eecba9a702ba37d47a04097b4c3c6
parent  25628d1307be31ae78d2e76f7f8e07425c6524f5
name age message
file .gitignore Fri May 02 13:34:39 -0700 2008 Added a validation to validate against the cont... [austin.bain]
file LICENSE Fri Apr 18 09:08:33 -0700 2008 Moved the License into its own file git-svn-i... [jyurek]
file README Thu Apr 17 13:10:52 -0700 2008 Moved the License into its own file [jyurek]
file Rakefile Fri Apr 18 07:22:33 -0700 2008 Rearranged stuff and added a gem build/deploy p... [jyurek]
directory generators/ Fri Oct 26 09:16:58 -0700 2007 Did some APIish stuff. git-svn-id: https://svn... [jyurek]
file init.rb Fri Apr 18 09:08:54 -0700 2008 Rearranged stuff and added a gem build/deploy p... [jyurek]
directory lib/ Tue May 13 13:15:22 -0700 2008 Version 2.1.2, with gem [jyurek]
directory tasks/ Tue May 13 10:23:48 -0700 2008 Added reprocess! method. The rake task will act... [jyurek]
directory test/ Tue May 13 10:50:35 -0700 2008 Added a test for reprocess\! [jyurek]
README
=Paperclip

Paperclip is intended as an easy file attachment library for ActiveRecord. The intent behind it was to keep setup as 
easy as possible and to treat files as much like other attributes as possible. This means they aren't saved to their 
final locations on disk, nor are they deleted if set to nil, until ActiveRecord::Base#save is called. It manages 
validations based on size and presence, if required. It can transform its assigned image into thumbnails if needed, and 
the prerequisites are as simple as installing ImageMagick (which, for most modern Unix-based systems, is as easy as 
installing the right packages). Attached files are saved to the filesystem and referenced in the browser by an easily 
understandable specification, which has sensible and useful defaults.

See the documentation for the +has_attached_file+ method for options.

==Usage

In your model:

  class User < ActiveRecord::Base
    has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
  end

In your migrations:

  class AddAvatarColumsToUser < ActiveRecord::Migration
    def self.up
      add_column :users, :avatar_file_name, :string
      add_column :users, :avatar_content_type, :string
      add_column :users, :avatar_file_size, :integer
    end

    def self.down
      remove_column :users, :avatar_file_name
      remove_column :users, :avatar_content_type
      remove_column :users, :avatar_file_size
    end
  end

In your edit and new views:

  <% form_for :user, @user, :url => user_path, :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) %>