lamrin
lamrin

Reputation: 1441

CSV wrong number of arguments error

I get the following error with CSV in (Rails3, ruby 1.9.2p0, ubuntu)

error in generate - wrong number of arguements(0 for 1)

Please, can you help me with the soluton for this?

I have used it in this code:

csv_data = CSV.generate do |csv|
  csv << [
  "S_No",
  "User ID",
  "Password"
  ]

  @password_array.each do |password|
    csv << [
    @user_name,
    @user_id,
    @password]
  end

end

I am then sending it in an email as an attachment:

UserMailer.export_csv(file_name,csv_data).deliver

Upvotes: 2

Views: 1691

Answers (2)

dklt
dklt

Reputation: 1700

I encountered exact same problem on Fedora15 with (ruby 1.8.7). Code below fixed the CSV.generate problem.

if RUBY_VERSION < "1.9"
require "rubygems"
require "faster_csv"
CSV = FCSV
else
require "csv"
end

Upvotes: 0

cam
cam

Reputation: 14222

You need to pass options to CSV.generate. If you don't care about any options, pass an emtpy hash:

CSV.generate({}) { |csv| ... }

Upvotes: 4

Related Questions