Commit efead1a1 by Mark Kremer Committed by Mike Burns

Specify default options in Rails 3.x configuration, README updated

parent 02f16c9f
......@@ -180,6 +180,33 @@ Lastly, you can also define multiple validations on a single attachment using `v
:content_type => { :content_type => "image/jpg" },
:size => { :in => 0..10.kilobytes }
Defaults
--------
Global defaults for all your paperclip attachments can be defined by changing the Paperclip::Attachment.default_options Hash, this can be useful for setting your default storage settings per example so you won't have to define them in every has_attached_file definition.
If you're using Rails 3.x you can define a Hash with default options in config/application.rb or in any of the config/environments/*.rb files on config.paperclip_defaults, these well get merged into Paperclip::Attachment.default_options as your Rails app boots. An example:
```ruby
module YourApp
class Application < Rails::Application
# Other code...
config.paperclip_defaults = {:storage => :fog, :fog_credentials => {:provider => "Local", :local_root => "#{Rails.root}/public"}, :fog_directory => "", :fog_host => "localhost"}
end
end
```
In earlier version of Rails you can also directly modify the Paperclip::Attachment.default_options Hash in an initializer, this method also works when you're not using Rails (and still works in Rails 3).
An example Rails initializer would look something like this:
```ruby
Paperclip::Attachment.default_options[:storage] = :fog
Paperclip::Attachment.default_options[:fog_credentials] = {:provider => "Local", :local_root => "#{Rails.root}/public"}
Paperclip::Attachment.default_options[:fog_directory] = ""
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"}
```
Storage
-------
......
......@@ -5,10 +5,11 @@ module Paperclip
require 'rails'
class Railtie < Rails::Railtie
initializer 'paperclip.insert_into_active_record' do
initializer 'paperclip.insert_into_active_record' do |app|
ActiveSupport.on_load :active_record do
Paperclip::Railtie.insert
end
Paperclip::Attachment.default_options.merge!(app.config.paperclip_defaults) if app.config.respond_to?(:paperclip_defaults)
end
rake_tasks { load "tasks/paperclip.rake" }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment