Visiting the page
localhost:3000/download_me
calls the controller action download_me in controller foo.
class foo < ApplicationController
def download_me
# a file is created here i.e. temp.csv in directory C:\
end
end
The controller shall create a temporary csv file and after that trigger a download in the browser that is visiting the page.
How can I do that?
Is there any reason you want to store the temp file on your server? If so something like this should suffice (using fastercsv, which you’ll need to install):
I suggest you probably don’t need to store the file though so just replace the FasterCSV.open line with:
Then spit out the csv as the response: