Rails3: Change location of temp (tmp) directory
Asked Answered
P

4

6

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?

Phytogeography answered 18/4, 2011 at 20:1 Comment(3)
As far as there is not any configuration about your temp folder (it is more about convention, that it is /Rails.root/tmp). But you can try to cheat a little: remove your tmp folder out of your Rails app and create a symlink for it as an ordinary Rails tmp dir. I don't know if it will work :))Paske
Symlinks are of good use to get Dropbox to sync files outside the Dropbox folder too... :)))Phytogeography
ok, I've just tried :) never used DropboxPaske
H
6

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.

Hermann answered 26/4, 2011 at 17:34 Comment(1)
Right you are...that is a creative solution. Thanks for the clarification that there is no configuration option!Phytogeography
J
6
ENV['TMPDIR'] = Rails.root.join('tmp')
Jurisdiction answered 11/5, 2011 at 2:17 Comment(2)
Thanks for your answer. However, I did not succeed with ENV['TMPDIR'] = '/tmp', no matter where I put this line, neither config files nor initializer. Could you please expand your answer?Phytogeography
try to put ENV['TMPDIR'] = Rails.root.join('tmp').to_s at your environment.rb fileJurisdiction
B
2

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

Basketball answered 27/11, 2012 at 3:54 Comment(0)
D
1

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]

Delafuente answered 26/1, 2013 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.