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
https://svn.thoughtbot.com/plugi...
The current release is
https://svn.thoughtbot.com/plugi...
The trunk is
https://svn.thoughtbot.com/plugi...
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) %>
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
Questions or feedback? Ask us on our blog, or contact me directly at jyurek@thoughtbot.com.
Copyright and License
Paperclip is © 2008, thoughtbot, inc. and is released under the same terms as Ruby.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
