Questions tagged [fastercsv]

Popular Ruby library/gem for working with CSV format files.

FasterCSV is a very popular Ruby gem for workin with CSV (comma-separated values) format files and data. It can import, export, and perform various other operations on data in CSV format.

164 questions
78
votes
2 answers

What is Ruby 1.9 standard CSV library?

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…
johan
  • 2,319
  • 9
  • 27
  • 37
31
votes
4 answers

How to write columns header to a csv file with Ruby?

I am having trouble writing columns to a csv file with Ruby. Below is my snippet of code. calc = numerator/denominator.to_f data_out = "#{numerator}, #{denominator}, #{calc}" File.open('cdhu3_X.csv','a+') do|hdr| hdr <<…
Joe
  • 743
  • 5
  • 10
  • 26
23
votes
9 answers

CSV - Unquoted fields do not allow \r or \n (line 2)

Trying to parse a CSV file, but still getting the error message Unquoted fields do not allow \r or \n (line 2).. I found here at SO similar topic, where was a hint to do following: CSV.open('file.csv', :row_sep => "\r\n") do |csv| but his…
user984621
  • 46,344
  • 73
  • 224
  • 412
21
votes
2 answers

fastercsv error with ruby 1.9.2

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…
sameera207
  • 16,547
  • 19
  • 87
  • 152
17
votes
3 answers

How do I robustly parse malformed CSV?

I'm processing data from government sources (FEC, state voter databases, etc). It's inconsistently malformed, which breaks my CSV parser in all sorts of delightful ways. It's externally sourced and authoritative. I must parse it, and I cannot have…
Sai
  • 6,919
  • 6
  • 42
  • 54
15
votes
3 answers

Overcoming a basic problem with CSV parsing using the FasterCSV gem

I have found a CSV parsing issue with FasterCSV (1.5.0) which seems like a genuine bug, but which I'm hoping there's a workaround for. Basically, adding a space after the separator (in my case a comma) when the fields are enclosed in quotes…
Olly
  • 7,732
  • 10
  • 54
  • 63
12
votes
1 answer

Example Application of FasterCSV

I'm very new to Ruby on Rails and web programming as well. Can someone show me some example of FasterCSV implementation.
johan
  • 2,319
  • 9
  • 27
  • 37
10
votes
2 answers

Custom Ruby CSV converters for multiple fields

I am importing a CSV file that contains fields that need to be converted as follows: "True" (string) -> true (boolean) "False" (string) -> false (boolean) "%m/%d/%Y" (string format) -> Date object "%m/%d/%Y %I:%M:%S %p" (string format) ->…
regulus
  • 939
  • 3
  • 13
  • 21
8
votes
4 answers

in rails, unable to override content-disposition filename

I am using Rails 3.1.0.rc8 and Chromium 15.0.874.102. I want to set the filename of a CSV download. I am following this SO solution, but find myself unable to modify the filename of the Content-Disposition header. Here is my code: module…
6
votes
3 answers

Using Ruby CSV creates Rails Records where string fields aren't queryable

I am trying to load seed data into my Rails application from a CSV file. I initially installed the fastercsv gem, only to find out that fastercsv has been deprecated in favor of the CSV library as of ruby 1.9. So I switched over to CSV after…
Paul Pettengill
  • 4,843
  • 1
  • 29
  • 33
6
votes
3 answers

How to pre-process CSV data for FasterCSV?

We're having a significant number of problems creating a bulk upload function for our little app. We're using the FasterCSV gem to upload data to a MySQL database but he Faster CSV is so twitchy and precise in its requirements that it constantly…
5
votes
3 answers

Rails FasterCSV "unquoted fields do not allow \r or \n"

I'm having an issue with FasterCSV and my rake db:seeds migration. I get the error: "rake aborted! Unquoted fields do not allow \r or \n (line 2)" on the following seeds.rb data: require 'csv' directory = "db/init_data/" file_name =…
Matthew Melone
  • 257
  • 5
  • 15
5
votes
2 answers

Importing CSV data into a ruby array/variable

I am trying to use a CSV as a settings file in a plugin for the SiriProxy project to use wake-on-lan. This project is based on ruby. So the csv is as follows: Name, MACAddress Desktop, 01-23-45-67-89-ab Computer, 02-46-81-02-46-cd and so on... So…
IMcD23
  • 445
  • 1
  • 7
  • 13
5
votes
3 answers

How do i skip over the first three rows instead of the only the first in FasterCSV

I am using FasterCSV and i am looping with a foreach like this FasterCSV.foreach("#{Rails.public_path}/uploads/transfer.csv", :encoding => 'u', :headers => :first_row) do |row| but the problem is my csv has the first 3 lines as the headers...any…
Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321
5
votes
2 answers

CSV renders in Safari view but I want it to download a file

I have configured a custom mime type: ActionController::Renderers.add :csv do |csv, options| self.content_type ||= Mime::CSV self.response_body = csv.respond_to?(:to_csv) ? csv.to_csv : csv end and a respond_to block in my…
JZ.
  • 21,147
  • 32
  • 115
  • 192
1
2 3
10 11