我想更改 Rails 4 中的临时目录。默认目录是 "#{Rails.root}/tmp"
但我想将其更改为其他内容,例如:"/tmp"
.
我已经找到如何从 "#{Rails.root}/tmp"
更改缓存目录:
config.cache_store = :file_store, '...'
config.assets.cache_store = :file_store, '...'
Sprockets 似乎仍在使用默认的 tmp 目录进行缓存。
在我的 Rails 3 项目中,我在 config/application.rb
中添加了以下内容:
if ENV['RAILS_TMP'].present?
config.cache_store = :file_store, ENV['RAILS_TMP'] + '/cache/'
config.assets.cache_store = :file_store, ENV['RAILS_TMP'] + '/assets'
config.sass.cache = false
end
设置 RAILS_TMP 会导致 tmp 目录发生变化。我有一种奇怪的感觉,这现在是硬编码的。
最佳答案
似乎有些库喜欢对值进行硬编码...参见:[1]
通过添加以下内容,您可以绕过硬编码值:
config.assets.cache_limit = 50.megabytes
config.assets.configure do |env|
env.cache = Sprockets::Cache::FileStore.new(
File.join(ENV['RAILS_TMP'], 'cache/assets'),
config.assets.cache_limit,
env.logger
)
end
关于ruby-on-rails - 在 Rails 4 中更改临时目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35077463/