Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (58 sloc) 3.476 kb
3e11f68 @Bertg Adding travis-ci status indicator
Bertg authored
1 h1. Delayed::Paperclip !https://secure.travis-ci.org/jstorimer/delayed_paperclip.png!
ddff0ea @jstorimer Added README
jstorimer authored
2
e90d726 @jstorimer README update
jstorimer authored
3 Delayed_paperclip lets you process your "Paperclip":http://github.com/thoughtbot/paperclip attachments in a background task with "delayed_job":http://github.com/tobi/delayed_job or "Resque":http://github.com/defunkt/resque.
ddff0ea @jstorimer Added README
jstorimer authored
4
5d9f4b0 @bigfleet Updating the README
bigfleet authored
5 h2. Why?
ddff0ea @jstorimer Added README
jstorimer authored
6
cf565c8 @joshk updated docs to explain the feature
joshk authored
7 The most common use case for Paperclip is to easily attach image files to ActiveRecord models. Most of the time these image files will have multiple styles and will need to be resized when they are created. This is usually a pretty "slow operation":http://www.jstorimer.com/ruby/2010/01/05/speep-up-your-paperclip-tests.html and should be handled in a background task.
e90d726 @jstorimer README update
jstorimer authored
8
9 I'm sure that everyone knows this, this gem just makes it easy to do.
6712736 @jstorimer Removed processing attribute.
jstorimer authored
10
e90d726 @jstorimer README update
jstorimer authored
11 h2. Installation
6712736 @jstorimer Removed processing attribute.
jstorimer authored
12
e90d726 @jstorimer README update
jstorimer authored
13 Install the gem:
1e95cd4 @jstorimer Inevitable README typos.
jstorimer authored
14
e90d726 @jstorimer README update
jstorimer authored
15 <pre><code>sudo gem install delayed_paperclip</code></pre>
1e95cd4 @jstorimer Inevitable README typos.
jstorimer authored
16
e90d726 @jstorimer README update
jstorimer authored
17 Add it to your environment.rb:
1e95cd4 @jstorimer Inevitable README typos.
jstorimer authored
18
e90d726 @jstorimer README update
jstorimer authored
19 <pre><code>config.gem 'delayed_paperclip'</code></pre>
20
21 Or, even better, to your Gemfile:
22
23 <pre><code>source "http://gemcutter.org"
24 gem 'delayed_paperclip'
25 </code></pre>
1e95cd4 @jstorimer Inevitable README typos.
jstorimer authored
26
e90d726 @jstorimer README update
jstorimer authored
27 Or install as a rails plugin:
1e95cd4 @jstorimer Inevitable README typos.
jstorimer authored
28
e90d726 @jstorimer README update
jstorimer authored
29 <pre><code>script/plugin install git://github.com/jstorimer/delayed_paperclip.git</code></pre>
6712736 @jstorimer Removed processing attribute.
jstorimer authored
30
31 Dependencies:
32 * Paperclip
e90d726 @jstorimer README update
jstorimer authored
33 * DJ or Resque
ddff0ea @jstorimer Added README
jstorimer authored
34
35 h2. Usage
36
37 In your model:
202e931 @jstorimer README formatting wtf
jstorimer authored
38
ddff0ea @jstorimer Added README
jstorimer authored
39 <pre><code>
40 class User < ActiveRecord::Base
41 has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
cf565c8 @joshk updated docs to explain the feature
joshk authored
42
ddff0ea @jstorimer Added README
jstorimer authored
43 process_in_background :avatar
cf565c8 @joshk updated docs to explain the feature
joshk authored
44 end
ddff0ea @jstorimer Added README
jstorimer authored
45 </code></pre>
46
47 Use your Paperclip attachment just like always in controllers and views.
48
caba4e0 @bigfleet Explanation about the selection between Resque and Delayed::Job
bigfleet authored
49 To select between using Resque or Delayed::Job, just install and configure your choice properly within your application, and delayed_paperclip will do the rest. It will detect which library is loaded and make a decision about which sort of job to enqueue at that time.
50
e90d726 @jstorimer README update
jstorimer authored
51 h3. Resque
984de7c @jstorimer Readme update
jstorimer authored
52
caba4e0 @bigfleet Explanation about the selection between Resque and Delayed::Job
bigfleet authored
53 Make sure that you have "Resque":http://github.com/defunkt/resque up and running. The jobs will be dispatched to the <code>:paperclip</code> queue, so you can correctly dispatch your worker. Configure resque and your workers exactly as you would otherwise.
e90d726 @jstorimer README update
jstorimer authored
54
55 h3. DJ
56
57 Just make sure that you have DJ up and running.
58
efd7fb0 @jstorimer Add example to README
jstorimer authored
59 h3. Displaying images during processing
cf565c8 @joshk updated docs to explain the feature
joshk authored
60
efd7fb0 @jstorimer Add example to README
jstorimer authored
61 In the default setup, when you upload an image for the first time and try to display it before the job has been completed, Paperclip will be none the wiser and output the url of the image which is yet to be processed, which will result in a broken image link being displayed on the page.
cf565c8 @joshk updated docs to explain the feature
joshk authored
62
df6ef41 @joshk refactored implementation to use a column called processing and not proc...
joshk authored
63 To have the missing image url be outputted by paperclip while the image is being processed, all you need to do is add a #{attachment_name}_processing column to the specific model you want to enable this feature for. This feature gracefully degrades and will not affect models which do not have the column added to them.
cf565c8 @joshk updated docs to explain the feature
joshk authored
64
efd7fb0 @jstorimer Add example to README
jstorimer authored
65 <pre><code>
66 class AddAvatarProessingToUser < ActiveRecord::Migration
67 def self.up
68 add_column :users, :avatar_processing, :boolean
69 end
70
71 def self.down
72 remove_column :users, :avatar_processing
73 end
74 end
75
76 @user = User.new(:avatar => File.new(...))
77 @user.save
78 @user.avatar.url #=> "/images/original/missing.png"
67aea03 @cpjolicoeur Delayed::Job.work_off is deprecated - use new method instead
cpjolicoeur authored
79 Delayed::Worker.new.work_off
efd7fb0 @jstorimer Add example to README
jstorimer authored
80
81 @user.reload
82 @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
83 </code></pre>
84
ddff0ea @jstorimer Added README
jstorimer authored
85 h2. What if I'm not using images?
86
322d460 @Bertg Asserting that any post processing will work
Bertg authored
87 This library works no matter what kind of post-processing you are doing with Paperclip.
ddff0ea @jstorimer Added README
jstorimer authored
88
89 h2. Does it work with s3?
90
7cd03a8 @jstorimer Contributor guide
jstorimer authored
91 Yes.
92
93 h2. Contributing
94
95 Checkout out CONTRIBUTING for more info.
Something went wrong with that request. Please try again.