Answer the question
In order to leave comments, you need to log in
Is it wise to store download files in the public directory?
There is an admin panel functionality that implements the download of a file with certain information.
The model method that implements this looks something like this:
class MyModel
....
def create_and_send_file
path = "/public/files/info.txt"
File.open(path, "w+") do |f|
MyModel.all.each do |obj|
f.write(obj.name)
end
end
send_file '/public/file/info.txt'
....
end
Answer the question
In order to leave comments, you need to log in
You didn't write what you want. In general, it is more reasonable to move the file creation itself out of the controller somewhere, so that it is convenient to test and run from background tasks.
When uploading a file, you do not need to save it to the public folder, and it is also advisable to delete it after uploading so that it does not take up space. Usually Tempfile
is used for this.
How to organize the return itself, with a separate controller or method - depends on the circumstances. If you need to give it somehow cunningly with caching or some other logic, it's better to put it in a separate controller. Otherwise, a method.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question