Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 49 lines (33 sloc) 1.844 kB
110df00 Extensive documentation, adding ability to crop thumbnails.
jyurek authored
1 =Paperclip
13318e6 Initial version
jyurek authored
2
0544f0f Doc changes
jyurek authored
3 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.
13318e6 Initial version
jyurek authored
4
5494e3c Docs and some splitting up of files because the single one was annoying.
jyurek authored
5 See the documentation for the +has_attached_file+ method for options.
110df00 Extensive documentation, adding ability to crop thumbnails.
jyurek authored
6
7 ==Usage
13318e6 Initial version
jyurek authored
8
9 In your model:
10
5494e3c Docs and some splitting up of files because the single one was annoying.
jyurek authored
11 class User < ActiveRecord::Base
2784b38 Huge refactoring.
jyurek authored
12 has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
110df00 Extensive documentation, adding ability to crop thumbnails.
jyurek authored
13 end
13318e6 Initial version
jyurek authored
14
36e6d07 Added sample migration to the README
jyurek authored
15 In your migrations:
16
17 class AddAvatarColumsToUser < ActiveRecord::Migration
18 def self.up
19 add_column :users, :avatar_file_name, :string
20 add_column :users, :avatar_content_type, :string
21 add_column :users, :avatar_file_size, :integer
22 end
23
24 def self.down
25 remove_column :users, :avatar_file_name
26 remove_column :users, :avatar_content_type
27 remove_column :users, :avatar_file_size
28 end
29 end
30
403e628 README update and default style
jyurek authored
31 In your edit and new views:
13318e6 Initial version
jyurek authored
32
5494e3c Docs and some splitting up of files because the single one was annoying.
jyurek authored
33 <% form_for :user, @user, :url => user_path, :html => { :multipart => true } do |form| %>
34 <%= form.file_field :avatar %>
110df00 Extensive documentation, adding ability to crop thumbnails.
jyurek authored
35 <% end %>
13318e6 Initial version
jyurek authored
36
37 In your controller:
38
110df00 Extensive documentation, adding ability to crop thumbnails.
jyurek authored
39 def create
2784b38 Huge refactoring.
jyurek authored
40 @user = User.create( params[:user] )
110df00 Extensive documentation, adding ability to crop thumbnails.
jyurek authored
41 end
403e628 README update and default style
jyurek authored
42
43 In your show view:
44
5494e3c Docs and some splitting up of files because the single one was annoying.
jyurek authored
45 <%= image_tag @user.avatar.url %>
46 <%= image_tag @user.avatar.url(:medium) %>
47 <%= image_tag @user.avatar.url(:thumb) %>
830c0aa Copy changes
jyurek authored
48
Something went wrong with that request. Please try again.