我正在使用两种不同的Rails App来管理照片上传。所以我需要将文件夹放在每个应用程序之外的某个位置,让他们来管理它。 Paperclip可以设置自定义路径,但如何使其与我的development environment
和production
不同?
has_attached_file :file,
:styles => {
:full => {
:geometry => "900x900",
:quality => "93"
}
},
:default_url => '',
:path => "/media/Websites/rails/uploads/:id/:style/:basename.:extension", # development path
:url => "/system/uploads/:id/:style/:basename.:extension"
答案 0 :(得分:3)
答案 1 :(得分:2)
您可以使用Rails.env.production?
方法,如下所示:
:path => Rails.env.production? ? 'production_path' : 'development_path'
答案 2 :(得分:0)
我喜欢你把这样的变量放在应用程序的配置文件中。
在config/application.rb
中,插入此配置行:
module MyApp
class Application < Rails::Application
# this is the bacon
config.paperclip_path = 'your/development/path'
end
end
和config/environments/production.rb
:
MyApp::Application.configure do
# First, check maybe you'll want to override this in a specific environment
config.paperclip_path = ENV['PAPERCLIP_PATH'] || '/your/production/path'
end
然后,您所要做的就是将has_attached_file
的路径参数更改为:
:path => "#{MyApp::Application.config.paperclip_path}/uploads/:id/:style/:basename.:extension",