21

I have an existing rails application I'm running on ruby 1.9.2 and linux its rails version is

rails 2.3.8

and it has a GEMFILE as well, in its vendor/gems directory it has 'fastercsv-1.5.4' gem
and in its migrations (in two migrations) it has required the gem 'fastercsv'

require 'fastercsv'

But when I do

rake db:migrate 

it fails the migration claiming

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

and I have found out the message comes from gems 'faster_csv.rb' file. as it has a condition to check the ruby version

if RUBY_VERSION >= "1.9"

  class FasterCSV
    def self.const_missing(*_)
      raise NotImplementedError, "Please switch to Ruby 1.9's standard CSV "  +
                                 "library.  It's FasterCSV plus support for " +
                                 "Ruby 1.9's m17n encoding engine."
    end

    def self.method_missing(*_)
      const_missing
    end

    def method_missing(*_)
      self.class.const_missing
    end
  end

-- and more code

Can someone tell me how to fix this issue. Please note 'fastercsv' has not been added to the GEMFILE.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
sameera207
  • 16,547
  • 19
  • 87
  • 152

2 Answers2

38

You don't need to use the FasterCSV gem with Ruby 1.9.2 as it is already included as standard library's CSV (e.g. require 'csv'). Just change references in your application from FasterCSV to CSV and remove the vendor/gems/fastercsv folder and it should Just Work(tm)

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
  • 3
    I only had to remove `fastercsv` from my Gemfile and change references from `FasterCSV` to `CSV`. I didn't have to delete any directories. Otherwise, this answer Just Worked(tm) for me. – Jared Beck Jul 01 '11 at 04:12
  • Also change the `require` statement from `'fastercsv'` to just `'csv'` per the accepted answer below. At first I thought I could remove the require statement after reading this answer. – colllin Sep 11 '12 at 23:03
18

I found the answer to my question

Its based on this post

What is Ruby 1.9 standard CSV library?

and as the solution i had to

require 'csv'

instead of

require 'fastercsv'

and change the FasterCSV to CSV

Community
  • 1
  • 1
sameera207
  • 16,547
  • 19
  • 87
  • 152
  • Same here, otherwise you end up with an uninitialized constant Object::CSV (NameError).. – Jenny Blunt Jul 07 '11 at 13:44
  • Oh i hope this works, cause i'm getting Object::CSV in my app and it's frusturating. Will report back and high five this answer if it's right! – pjammer Jul 11 '11 at 18:35