title: How can I set paperclip's storage mechanism based on the current Rails environment?
body: <p>I have a rails application that has multiple models with paperclip attachments that are all uploaded to S3.  This app also has a large test suite that is run quite often. The downside with this is that a ton of files are uploaded to our S3 account on every test run, making the test suite run slowly.  It also slows down development a bit, and requires you to have an internet connection in order to work on the code. </p>
  
  <p>Is there a reasonable way to set the paperclip storage mechanism based on the Rails environment? Ideally, our test and development environments would use the local filesystem storage, and the production environment would use S3 storage.</p>
  
  <p>I'd also like to extract this logic into a shared module of some kind, since we have several models that will need this behavior. I'd like to avoid a solution like this inside of every model:</p>
  
  <pre><code>### We don't want to do this in our models...
  if Rails.env.production?
    has_attached_file :image, :styles =&gt; {...},
                      :path =&gt; "images/:uuid_partition/:uuid/:style.:extension",
                      :storage =&gt; :s3,
                      :url =&gt; ':s3_authenticated_url', # generates an expiring url
                      :s3_credentials =&gt; File.join(Rails.root, 'config', 's3.yml'),
                      :s3_permissions =&gt; 'private',
                      :s3_protocol =&gt; 'https'
  else
    has_attached_file :image, :styles =&gt; {...},
                      :storage =&gt; :filesystem
                      # Default :path and :url should be used for dev/test envs.
  end
  </code></pre>
  
  <p><strong>Update:</strong> The sticky part is that the attachment's <code>:path</code> and <code>:url</code> options need to differ depending on which storage system is being used.</p>
  
  <p>Any advice or suggestions would be greatly appreciated! :-)</p>