-
-
Save markevans/2036284 to your computer and use it in GitHub Desktop.
### EXAMPLE: USING DRAGONFLY WITH S3 ON HEROKU ### | |
#### CURRENT API ##### | |
# in initializer file | |
require 'dragonfly' | |
app = Dragonfly[:images] | |
app.configure_with(:imagemagick) | |
app.configure_with(:rails) | |
app.configure do |c| | |
if Rails.env.production? | |
c.datastore = Dragonfly::DataStorage::S3DataStore.new( | |
:bucket_name => 'my-bucket-name', | |
:access_key_id => ENV['S3_KEY'], | |
:secret_access_key => ENV['S3_SECRET'] | |
) | |
end | |
c.some_other_option = 'blah' | |
end | |
app.define_macro(ActiveRecord::Base, :image_accessor) | |
# in Model: | |
class MyModel < ActiveRecord::Base | |
image_accessor :image | |
end | |
####################################################################### | |
#### NEW API ##### | |
# in initializer file: | |
require 'dragonfly' | |
Dragonfly[:app].configure do | |
use :imagemagick | |
use :rails | |
datastore :s3 do | |
bucket_name 'my-bucket-name' | |
access_key_id ENV['S3_KEY'] | |
secret_access_key ENV['S3_SECRET'] | |
end if Rails.env.production? | |
some_other_option 'blah' | |
end | |
# in Model: | |
class MyModel < ActiveRecord::Base | |
dragonfly_accessor :image | |
end |
I love the new configuration api.
About the dragonfly_accessor, that can help to avoid thinking that dragonfly can manage only image.
About the switching app directly on the dragonfly_accessor. It can be good choice. Because chaging app its hard actually.
👍 on this new api
New API looks great! But I think this would cleaner:
datastore :s3, :env => [:production, :staging] do
bucket_name 'my-bucket-name'
access_key_id ENV['S3_KEY']
secret_access_key ENV['S3_SECRET']
end
what do you think?
Nice idea, though I'm not so keen on that because then it depends on Rails (at the moment it would work anywhere)
I guess I could use RACK_ENV or something, but still I'd rather not complicate the "datastore" configuration method - it should simply configure the datastore, and any conditions should go outside
what do you reckon?
The env option can't work because in rack application it's define by RACK_ENV but RAILS_ENV in rails.
@shingara - yes exactly I agree - avoiding thinking it's only for images is a benefit
Note: there would be a default dragonfly app Dragonfly[:app]
If you wanted another dragonfly app, e.g. Dragonfly[:videos], you would configure it as usual but have to specify it when declaring the accessor, i.e.