Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fasterCSV for ruby 1.9.3?

I'm trying to export my report in a CSV format document. For that i used fasterCSV but,i faced

Please switch to Ruby 1.9's standard CSV library.
It's FasterCSV plus support for Ruby 1.9's m17n encoding engine.

error. Can any one help me to solve this error? my code as follows

csv_string = FasterCSV.generate do |csv|
  csv << ["Client_name", "Created_at", "User type"]
  @client_reports.each do |client_reports|
    csv << [client_reports.email, client_reports.created_at,client_reports.role_name]
  end
end
send_data csv_string,
  :type => 'text/csv; charset=iso-8859-1; header=present',
  :disposition => "attachment; filename=product_stock.csv"

So please help me to resolve this in Ruby 1.9.3. It work's fine in Ruby 1.8.7.

Or if you can suggest me any other resource please help me out with that example?

like image 487
Ferdy Avatar asked Dec 21 '22 18:12

Ferdy


1 Answers

As of Ruby 1.9.2 FasterCSV is already included as standard library's CSV. Just change references in your application from FasterCSV to CSV and it should work. Check out the docs and this new Railscast.

like image 188
Syed Aslam Avatar answered Dec 31 '22 12:12

Syed Aslam