Heroku允許您通過應用程序中的每個dyno /進程開始使用的持久環境變量來配置任何您喜歡的任何東西。環境變量不在同一個應用程序的登臺和生產版本之間共享。利用這一點。
has_attached_file :photo,
:styles => ...,
:path => ...,
:storage => :s3,
:bucket => ENV['S3_BUCKET'], # <--- over here
:s3_credentials => {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
}
然後:
# Configure the "staging" instance
$ heroku config:add \
RACK_ENV=production \
S3_KEY=my-staging-key \
S3_SECRET=my-staging-secret \
S3_BUCKET=my-staging-bucket \
--app my-staging-app-name
# Configure the "production" instance
$ heroku config:add \
RACK_ENV=production \
S3_KEY=my-production-key \
S3_SECRET=my-production-secret \
S3_BUCKET=my-production-bucket \
--app my-production-app-name
請注意,您的應用程序的每個實例有一個RACK_ENV=production
。不要使用Rails環境來區分應用程序的實例。相反,您的應用程序應該期望使用環境變量來配置特定於實例的方面。
你如何寫回形針conf? – apneadiving
呼吸暫停,你在說什麼文件? – sscirrus
在你的模型中,你如何將你的s3配置傳遞給回形針? – apneadiving