English 中文(简体)
ccsv in Mouy 1.9 and CSV:Writer
原标题:write csv in ruby 1.9 and CSV::Writer

i 拥有一部与废墟1.87做罚款的法典,但与废墟1.9做工。 它说,CSV:Writer虽未申报,但仍属于教义的一部分。 在迅速合并后, c虫是否发生了变化?

我的法典:

require  csv 

def self.export_csv
 file_name = File.join(RAILS_ROOT,  public , csv ,"#{start_date_f}_#{end_date_f}.csv")
 return file_name if File.exist?(file_name)
 @results = find(:all)
 header_row = []
 outfile = File.open(file_name,  wb )
 CSV::Writer.generate(outfile) do |csv|
      header_row = [ gateway_id , created ,  gateway_status_id ,  panel_id ,   panel_status , volts_out ,  amps_out ,  temp , aid  , sid ,  pisid ]
      csv << header_row
  end
end

收到以下错误:姓名:未开始的普通社会保障金:

Note that require csv is there. i try it in my console, when i do the require csv , it works, but as soon as i call CSV::Writer i receive that error. This code works fine with ruby 1.87, so it makes me think that it is a ruby 1.9 csv problem since it was merged with fasterCSV.

最佳回答

茨夫图书馆仍然存在,但该中心:没有。 根据1.9.0中弹片:

# I m sure I ll miss something, but I ll try to mention most of the major
# differences I am aware of, to help others quickly get up to speed:
#
# === CSV Parsing
#
# * This parser is m17n aware.  See CSV for full details.
# * This library has a stricter parser and will throw MalformedCSVErrors on
#   problematic data.
# * This library has a less liberal idea of a line ending than CSV.  What you
#   set as the <tt>:row_sep</tt> is law.  It can auto-detect your line endings
#   though.
# * The old library returned empty lines as <tt>[nil]</tt>.  This library calls
#   them <tt>[]</tt>.
# * This library has a much faster parser.
#
# === Interface
#
# * CSV now uses Hash-style parameters to set options.
# * CSV no longer has generate_row() or parse_row().
# * The old CSV s Reader and Writer classes have been dropped.
# * CSV::open() is now more like Ruby s open().
# * CSV objects now support most standard IO methods.
# * CSV now has a new() method used to wrap objects like String and IO for
#   reading and writing.
# * CSV::generate() is different from the old method.
# * CSV no longer supports partial reads.  It works line-by-line.
# * CSV no longer allows the instance methods to override the separators for
#   performance reasons.  They must be set in the constructor.

不久后,就有一个实例,说明如何逐行(以及其他书面方法):

# === To a File
#
#   CSV.open("path/to/file.csv", "wb") do |csv|
#     csv << ["row", "of", "CSV", "data"]
#     csv << ["another", "row"]
#     # ...
#   end
问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签