thoughtbot / paperclip
- Source
- Commits
- Network (293)
- Issues (93)
- Downloads (23)
- Wiki (6)
- Graphs
-
Tree:
e35fa9e
jyurek (author)
Thu Mar 20 08:58:47 -0700 2008
commit e35fa9eb8eb78a975c16b3a4a7e04113dd5c76a1
tree f5e5e46c88ed32b8e2e0c9d05e859e6a7d5ef626
parent 30c2be58004f515c1a75413ae224c5f55c433643
tree f5e5e46c88ed32b8e2e0c9d05e859e6a7d5ef626
parent 30c2be58004f515c1a75413ae224c5f55c433643
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 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) %>

