I am looking to change the temporary directory in Rails 4. The default is "#{Rails.root}/tmp"
but I would like to change it to something else, e.g.: "/tmp"
.
I have found how to change the cache directories from "#{Rails.root}/tmp"
:
config.cache_store = :file_store, '...'
config.assets.cache_store = :file_store, '...'
Sprockets seems to still be using the default tmp directory for caching.
In my Rails 3 project, I added the following in my 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
Setting RAILS_TMP causes the tmp dir to change. I have an odd feeling that this is now hard coded.
It seems that some libraries like to hard code values... See: [1]
By adding the following you can get around the hard coded value:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With