views:

24

answers:

1

Hi,

I've a model which use paperclip, in dev env I want to store files on the file system.

In production I want to store them on my s3 account.

How to configure my model to reflet this difference?

Here is my model

class Photo < ActiveRecord::Base
  has_attached_file :photo, :styles => { :medium => "200x200>", :thumb => "100x100>" },
                    :storage => :s3, 
                    :s3_credentials => "#{Rails.root}/config/s3.yml", 
                    :path => "/:style/:filename"
end
+1  A: 

The quick and dirty method is to use a simple if statement:

class Photo < ActiveRecord::Base
  if Rails.env.production?
    has_attached_file :photo, :styles => { :medium => "200x200>", :thumb => "100x100>" },
                      :storage => :s3, 
                      :s3_credentials => "#{Rails.root}/config/s3.yml", 
                      :path => "/:style/:filename"
  else
    # store them locally
  end
end
Ryan Bigg