-->

Rails3: Change location of temp (tmp) directory

2019-02-22 16:43发布

问题:

I usually develop in my local Dropbox folder. Some files in the tmp-folder get locked by the browsers (and keep Dropbox busy), Growl throws exceptions and so on.

Therefore I am looking for a configuration setting to put the tmp-folder outside the Rails-app bundle. Is that possible?

回答1:

Not the answer you're looking for - but I can definitively say that there's no configuration option to change where Rails thinks the tmp folder is. The location is hard coded in many different places in the Rails codebase.

Looks like the symlink will sync the original file, so you'll probably have the same locking problems.

If you do, then you can just use the symlinks the other way around to solve your problem, ie. create your project outside your dropbox, and symlink everything other than tmp into a folder in your dropbox.

So you might have your Rails app in ~/work/rails_project/<all the rails dirs including tmp> and then you'll have a corresponding dir in your dropbox, like ~/dropbox/rails_project and then inside that dir you'll manually create a bunch of symlinks and then delete the tmp one, using bash you'd do this:

$ for f in ~/work/rails_project/*; do ln -s $f; done
$ rm tmp

You'd need to remember to run that again if you ever added a new file/directory to the root of your app.



回答2:

ENV['TMPDIR'] = Rails.root.join('tmp')


回答3:

you can't change tmp directory, but you can configure tmp cache directory.

# config/application.rb
config.cache_store                   = [ :file_store, "/tmp/rails-cache/" ]
config.assets.cache_store            = [ :file_store, "/tmp/rails-cache/assets/#{Rails.env}/" ]

you can read more at configuration.rb



回答4:

You can exclude a directory from being synced in Dropbox by using Selective Sync: http://www.dropbox.com/help/175/en

Basically select the Dropbox preferences and go in Advanced. Select then Selective Sync and look for the folder that you want to exclude from syncing [there is also an advanced view if you have to go in a deeper than 1st level dir depth]