Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I save uploaded files in Rails?

I've tried to find the documentation file handling in Rails, without success. Here's the link to the File class (specified by the docs for file_filed_tag): http://api.rubyonrails.org/classes/File.html

I figure there's got to be a better set of source docs. My main question is about where can I save a file that is not publicly accessible. I'm interested in using file uploaded files temporarily for "wizard" like purposes for users.

like image 220
chrisp Avatar asked Feb 17 '23 15:02

chrisp


1 Answers

The Rails documentation only mentions this in passing The source that handles uploads is https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/upload.rb

You could use the gem "paperclip" to handle the file upload for you:

https://github.com/thoughtbot/paperclip

It is conventional to store your uploaded files in public/system, the default configuration in paperclip is:

:rails_root/public/system/:class/:attachment/:id_partition/:style/:filename

but you can change it to another main folder if you want to keep it out of public:

:rails_root/private/:class/:attachment/:id_partition/:style/:filename
like image 120
bjelli Avatar answered Mar 29 '23 16:03

bjelli