forked from thoughtbot/paperclip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jon Yurek
committed
Jun 3, 2008
1 parent
cf3a735
commit edfff2f
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
=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) %> | ||
|