开发者

Rails diff model config in dev or prod environment

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>" },
                    :开发者_JAVA百科storage => :s3, 
                    :s3_credentials => "#{Rails.root}/config/s3.yml", 
                    :path => "/:style/:filename"
end


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜