From ajax I call my export action in my controller
def export
data_filtered = eval(params[:data_filtered][9..-2])
CSV.open("data.csv", "wb") do |csv|
csv << data_filtered.first.keys
data_filtered.each do |hash|
csv << hash.values
end
end
end
Currently this does indeed create a file called data.csv on my computer but it doesn't show any evidence of actually doing so. I want the file to be downloaded by the browser and show up in the browser downloads and also in my downloads folder.
EDIT:
def export
data_filtered = eval(params[:data_filtered][9..-2])
csv_file = CSV.generate({}) do |csv|
csv << data_filtered.first.keys
data_filtered.each do |hash|
csv << hash.values
end
end
send_data csv_file, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; filename=tester1.csv"
end