2010-03-28 40 views
0

我有一个使用回形针的模型,在开发环境中我想将文件存储在文件系统上。开发或产品环境中的Rails diff模型配置

在制作中,我想将它们存储在我的s3帐户中。

如何配置我的模型以反映这种差异?

这里是我的模型

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

的快速和肮脏的方法是使用一个简单的if声明:

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