2

我用回形针什么样的环境文件存储在Amazon S3上,而这个代码,与aws-s3宝石一起,让我来存储文件上传与Amazon S3:如何有条件地根据你在

has_attached_file :photo, 
    :styles => { 
    :tiny => "25x25#", 
    :shown => "40x40#", 
    :thumbnail => "50x50#", 
    :small => "150x150>", 
    :medium => "300x300>" }, 
    :default_url => "/images/default_:style.jpg", 
    :storage => :s3, 
    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", 
    :path => "profile/:attachment/:style/:id.:extension" 

但是,我不想在我的开发环境中将文件存储在Amazon S3上。我如何在我的应用程序中设置?

回答

1

你很可能这样做

:storage => Rails.env.production? ? :s3 : :whatever 
+0

什么应该':无论是什么?因为通常我会忽略':storage',如果我不想在s3上存储文件... – 2011-06-13 04:16:03

+0

nil应该做的窍门 – 2011-06-13 04:23:08

+1

可能是:文件系统,它应该将其保存为本地文件 – PerfectlyNormal 2011-06-13 04:23:11

1

在environment.rb文件的末尾:

APP_CONFIG = YAML.load_file("#{Rails.root.to_s}/config/config.yml")[Rails.env] 

在配置/ config.yml:

development: 
    use_amazon: false 

test: 
    use_amazon: false 

production: 
    use_amazon: true 

而在你的控制器:

if APP_CONFIG['use_amazon'] 
    #USING AMAZON S3 
else 
    #USING SOMETHING ELSE 
end 

这应该工作。 祝你好运!