I am using the csv library within ruby 1.9, and trying to follow the example for a table shown here:
My code is as follows:
<% require 'csv' %>
<% table = CSV.parse("public/assets/file.csv", :headers => true, :header_converters => :symbol) %>
<%= table %>
But the above returns a blank screen where I am expecting it to show the file.
Also when I try to view table[0].fields, I get the error
undefined method `fields' for nil:NilClass
The following works when reading a csv file however:
<% b = CSV.read("public/assets/khq.csv") %>
<%= b %>
Is there something I am doing incorrectly with the table example?
For 1.9.2, Try
or
FYI, CSV.parse is for string, not for a file.
You may take a look at document here at http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV.html#method-c-parse