public
Description: Thoughtbot's Paperclip in a universal gem for both Rails and Merb
Homepage: http://www.jaikoo.com
Clone URL: git://github.com/jaikoo/universal-paperclip.git
Search Repo:
Jonathan Conway (author)
Fri Apr 11 14:44:59 -0700 2008
commit  40b340f819ab3ae698b04f94fa669a923837ae0c
tree    8d7495643b671f376f2d8076c611e9188fd5765c
parent  b2755983957cda7fcf977e369aee242dbd64dfc7
name age message
folder History.txt Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder License.txt Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder Manifest.txt Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder README.txt Fri Apr 11 14:44:59 -0700 2008 Updated the README file with instructions on ho... [Jonathan Conway]
folder Rakefile Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder config/ Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder generators/ Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder lib/ Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder log/ Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder pkg/ Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder script/ Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder setup.rb Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder tasks/ Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder test/ Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
folder website/ Fri Apr 11 04:42:24 -0700 2008 first commit [Jonathan Conway]
README.txt
I'm going through turning everything into a universal gem so that it can be used for both Rails and Merb.
This one is the Paperclip plugin from Thoughtbot.

To build the gem run 'rake package' then 'sudo gem install pkg/universal_paperclip-0.0.1.gem'

In Merb edit init.rb and add:

dependency 'paperclip'

In Rails created a attachments.rb file in your initializers dir and add the line:

require 'paperclip'

Cheers

Jaikoo


=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 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) %>