78

When I try the FasterCSV gem on my application I get this error:

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

By the way, I'm using Rails 3, Ruby 1.9.2, and Rubygems 1.4.

Can someone explain to me please how to use the standard CSV library for Ruby 1.9. I don't have any idea at all because I'm very new to Rails.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
johan
  • 2,319
  • 9
  • 27
  • 37

2 Answers2

140

Ruby 1.9 has adopted FasterCSV as its built-in CSV library. However, it's in the standard library rather than Ruby 1.9's core, so you need to manually require it in your application.

After adding a

require 'csv'

to your code, you can then do things such as

CSV.parse("this,is,my,data")

See Ruby 1.9's standard library CSV documentation for information on using the library.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Dylan Markow
  • 123,080
  • 26
  • 284
  • 201
  • Thank You so much. How I wish I can vote for your answer but the system is telling me to have at least 15 reputation. What do the parameters in CSV.parse("this,is,my,data") mean? I know thiss is too much too ask but I'm really new to ruby on rails. – johan Feb 16 '11 at 06:37
  • 3
    those are not parameters... that's just an example he's giving of a string "this,is,my,data" that is being parsed – jpw Feb 19 '11 at 19:45
  • Thank you so much. All I thought those are parameters. I already solved the problem. I already know how to import CSV data in Ruby 1.9.2. – johan Feb 21 '11 at 06:02
-6

See how I solved this problem!

require 'fastercsv'
require 'csv'

secrecy_levels_array = [['SUPERSECRET', 'Supersecret Data', "Tell No One"],
['SEMISECRET', 'Semisecret Data', 'Tell Some People'],
['UNSECRET', 'Unsecret Data', 'Tell Everyone']]

puts '\n'
secrecy_levels_array.each do |line|
  puts line.to_csv
end
  • 4
    -1 You didn't even bother to understand the existing three-year-old question & answer before posting. If you're coming in after three years your answer should be more up-to-date, but it is not. – Mark Thomas May 22 '14 at 01:12