Home Export csv file not working in safari using Ruby on Rails
Reply: 0

Export csv file not working in safari using Ruby on Rails

Aravi
1#
Aravi Published in 2017-11-09 04:52:34Z

I need to export the data to csv format. The following code working fine in firefox, but not working in safari as expected.

report.html.erb

<%= link_to 'Download CSV', reports_path(format: :csv), class: 'white' %>

report.csv.erb

<%- headers = [' Date ',   ' Type ',   'Amount ',    ' Amount '] -%>
<%= CSV.generate_line headers %>
<% if @reports.present? %>
<%- @reports.each do |report| -%>
<%= CSV.generate_line([report['Date'],
                       report['Type'],
                       report['Amount'],
                       report['Amount']]).html_safe -%>
<%- end -%>
<% end %>

reports_controller.rb

respond_to do |format|
      format.html
      format.csv do
        log('info', current_user.email, 'File creating for Cash book..')
        headers['Content-Disposition'] = 'attachment; filename="filename"'
        headers['Content-Type'] ||= 'text/csv'
      end
    end

can anyone helpme?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.31149 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO