forked from finknottle/Paperclip-Storage-Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
54 lines (40 loc) · 2.76 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Paperclip::Storage::Cloudfiles extension
===============
This is an extension to the popular paperclip plugin, Cloudfiles fork
This is NOT the paperclip plugin itself. It needs the paperclip plugin to be installed in your vendor/plugins directory
For information on the paperclip plugin itself, see the excellent tutorial on http://github.com/thoughtbot/paperclip
For information on the cloudfiles fork of the paperclip plugin, see: https://github.com/minter/paperclip
Remade for Cloudfiles, based off of finknottle's Paperclip-Storage-Extension: https://github.com/finknottle/Paperclip-Storage-Extension
What this extension does
========================
The paperclip plugin is great to add files to your existing model without requiring an additional model.
A forked version of papercli[ has a module called Cloudfiles which allows you to store your uploaded files in your Cloudfiles account. The buckets can be defined in the configuration YAML file, typically called #{RAILS_ROOT}/config/rackspace_cloudfiles.yml.
The configuration file looks like
development:
username: yourusernamehere
api_key: yourapikeyhere
container: dev_avatars
production:
username: yourusernamehere
api_key: yourapikeyhere
container: avatars
The problem though is that when you are developing on your machine, or creating a test machine, but with the production environment, then you want to copy the db from your production machine, and play with the data. At this point, you usually want your files (typically images) to be available for your environment. But at the same time, you don't want to change the files in your production bucket when you change them in your development or test environment.
This is where this extension comes in. The extension allows you to add two more configuration options to your YAML file. So that, the file then looks like
development:
username: yourusernamehere
api_key: yourapikeyhere
container: dev_avatars
container_alt: avatars
testing: true
production:
username: yourusernamehere
api_key: yourapikeyhere
container: avatars
testing: false
You can add the additional two options through a capistrano recipe or a chef recipe, based on your deployment mechanism.
Thus, in your production environment, everything will work as before, all reads and writes will occur on the production bucket defined in the configuration bucket:
However, in an environment with testing set to true, the reads will be done from your container if it exists, but will check your production bucket if it does not. The writes and deletes will still be done from your bucket.
Installation
============
Simply add this file to the #{RAILS_ROOT}/lib/ directory, and call it in the environment.rb file below the Rails Initializer block
require 'lib/paperclip_storage_ext'