I have a csv file and in my controller:
uploaded_file = params[:upload][:csv].read
@rows << FasterCSV.parse(uploaded_file)
I want to put in @rows only the first 10 lines but the read method
reads all the file.
How can I do?
I have a csv file and in my controller:
uploaded_file = params[:upload][:csv].read
@rows << FasterCSV.parse(uploaded_file)
I want to put in @rows only the first 10 lines but the read method
reads all the file.
How can I do?
On 26 March 2011 18:52, Mauro [email protected] wrote:
I have a csv file and in my controller:
uploaded_file = params[:upload][:csv].read
@rows << FasterCSV.parse(uploaded_file)I want to put in @rows only the first 10 lines but the read method
reads all the file.
I think you can do something like
FasterCSV.foreach( uploaded_file) do |row|
end
Colin
On 26 March 2011 22:06, Colin L. [email protected] wrote:
FasterCSV.foreach( uploaded_file) do |row|
do something for first 10 rows then break out
end
I’ve solved with:
uploaded_file = params[:upload][:csv].read
FasterCSV.parse(uploaded_file) do |row|
@rows[i] = row
i += 1
break row if i == 10
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs