Reputation: 1975
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
Upvotes: 0
Views: 4770
Reputation: 23661
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
Upvotes: 1