My rails application runs on a Ubuntu server machine.
I need to create temporary files in order to "feed" them to a second, independent app (I'll be using rake tasks for this, in case this information is needed)
My question is: what is the best way of creating temporary fields on a rails application?
Since I'm in ubuntu, I could create them on /tmp/whatever
, but what would work only in linux.
I'd like my application to be as portable as possible - so it can be installed on Windows machines & mac, if needed.
Any ideas?
Thanks a lot.
In any case, all arguments ( basename , tmpdir , mode , and **options ) will be treated as ::new. Creates a temporary file with permissions 0600 (= only readable and writable by the owner) and opens it with mode “w+”. The temporary file will be placed in the directory as specified by the tmpdir parameter.
tmp files are not created by Jungle Disk, but are usually created by programs like Microsoft Office and Adobe Acrobat. These are considered 'working' files and are where these programs store their edited data before committing the opened file to a save.
Open your File Explorer (it's usually the first button on your desktop taskbar, looks like a folder). Go to the "This PC" section on the left, and then double-click your C: drive. On the Home tab at the top, click "New Folder" and name it "Temp".
tmp/
is definitively the right place to put the files.
The best way I've found of creating files on that folder is using ruby's tempfile library.
The code looks like this:
require 'tempfile' def foo() # creates a temporary file in tmp/ Tempfile.open('prefix', Rails.root.join('tmp') ) do |f| f.print('a temp message') f.flush #... do more stuff with f end end
I like this solution because:
Rails apps also have their own tmp/
directory. I guess that one is always available and thus a good candidate to use and keep your application portable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With