在Rails 4中更改临时目录

时间:2016-01-29 05:23:31

标签: ruby-on-rails ruby ruby-on-rails-4

我希望更改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目录发生变化。我有一种奇怪的感觉,现在这是硬编码。

3 个答案:

答案 0 :(得分:2)

似乎某些库喜欢硬编码值...请参阅:[1]

通过添加以下内容,您可以绕过硬编码值:

{{1}}

答案 1 :(得分:0)

创建一个类似over_ride_temp_path.rb的新初始化文件,并在其中粘贴以下代码。

class Dir

  def self.tmpdir
    <path of the directory to be used as temp>
  end

end

答案 2 :(得分:0)

我不确定这是否可以正常运行,但在./config/application.rb中,请尝试:

config.paths.add("tmp", with: ENV['RAILS_TMP'])