I have a form (Rails) which allows me to load a .csv file using the file_field
.
In the view:
<% form_for(:upcsv, :html => {:multipa
Just to demonstrate what IO#readlines does:
if you had a file like this: "asdflkjasdlkfjsdakf\n asdfjljdaslkdfjlsadjfasdflkj\n asldfjksdjfa\n"
in rails you'd do, say:
file = File.open(File.join(Rails.root, 'lib', 'file.json'))
lines_ary = IO.readlines(file)
lines_ary.count #=> 3
IO#readlines converts a file into an array of strings using the \n (newlines) as separators, much like commas so often do, so it's basically like
str.split(/\n/)
In fact, if you did
x = file.read
this
x.split(/\n/)
would do the same thing as file.readlines
** IO#readlines can be really handy when dealing with files which have a repeating line structure ("child_id", "parent_ary", "child_id", "parent_ary",...) etc