0

In my rails app, I can download data as csv file.

This is my current code

response_to do |format|
   format.csv {send_data #MY_DATA#}
end

Instead of this code, I want to save the csv file on server.

How can I generate csv file and save the file on the server

Thanks

1 Answer 1

1

You can use this to generate a CSV on server.

CSV.open("#{Rails.root}/public/file.csv", "wb") do |csv|
  csv << ["row", "of", "CSV", "data"]
  csv << ["another", "row"]
  # ...
end
Sign up to request clarification or add additional context in comments.

1 Comment

your code worked, but I need to save the file on s3 after generate AwsWrapper.write_object('aa_sites_files', s3key, "MYFILE", nil), Do I need to save the file first on server? or there is the option to generate the file and save it on S3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.