I upload through a form a file and in the controller this file read. My problem is, that I don’t know, hot to detect the end of the file (=> when stop a loop). This part of code looks like this:
dat = params[:data]
while(d = dat.read)
puts d
break if d.eof #this doesn't work
end
The result of this part is (except the error about eof) infinity while looping.
From http://ruby-doc.org/core-1.9.3/IO.html#method-i-read:
If length is omitted or is nil, it reads until EOF and the encoding conversion is applied. It returns a string even if EOF is met at beginning.
So I guess you should just do
dat.readEdit: if you want all the lines of the file, use
dat.readlines– this will return anArrayofStrings