Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change temporary directory in Rails 4

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.

like image 608
squirly Avatar asked Jan 29 '16 05:01

squirly


1 Answers

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
like image 123
squirly Avatar answered Nov 17 '22 20:11

squirly