I have tried length method to get the row count and it took at least 2 mins to return the row count. Length method is fast up to 10 000 and it's too slow when it exceeds 100 000 rows. Is there a way to get the row count with in 2 sec even file contains over 100k rows?
I have used the following code.
file = params[:file]
f = File.open(file.path, 'r:iso-8859-1:utf-8')
csv_file = CSV.parse(f.read, :headers => true, :converters => :all, :header_converters => lambda {|h| h.to_s.include?(' ') ? h.downcase.parameterize.underscore : h})
csv_file.length