Rails3: Change location of temp (tmp) directory

2019-02-22 16:23发布

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?

4条回答
淡お忘
2楼-- · 2019-02-22 16:52

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

查看更多
聊天终结者
3楼-- · 2019-02-22 17:01

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]

查看更多
看我几分像从前
4楼-- · 2019-02-22 17:12
ENV['TMPDIR'] = Rails.root.join('tmp')
查看更多
够拽才男人
5楼-- · 2019-02-22 17:19

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.

查看更多
登录 后发表回答