Importing CSV and Excel in rails 4 and ruby 2.0

You can use a single gem 'roo' for reading all types of file, instead of rubyXL, spreadsheet etc. multiple gems for different files(.xls, .xlsx).
You can check [here railscasts][1] for importing csv and excel import in ruby 1.9.3.

But this code snippet is not working with Ruby 2.0.

As [this episode][2] used gem 'roo' for reading files and gem 'roo' has been updated for rails 4.0.

So you need to do some code changes to work [it][3] with rails 4.0

Changes are:

  1. In Method: self.open_spreadsheet(file), nil, :ignore) =>, nil, :ignore), nil, :ignore) =>, nil, :ignore), nil, :ignore) =>, nil, :ignore)
  1. Remove
    require 'iconv'
    from config/application.rb

    For more about roo gem [click here][4]

Sunil Sharma

I am a Ruby on Rails developer, passionate about building interesting and innovative web and mobile apps. | Ruby on Rails | Ember.js | Cordova | Travelling | Party | Trekking ...

Read More