This import method imports all of the records in a single query.
nTip The :validates=>false option turns off validation. In this case, it doesn??™t make a difference,
since the model doesn??™t include any validation. But, in general, if you??™re dealing with data that??™s guaranteed
to be in a certain format, and you have expensive validations in your models, you can speed up
ActiveRecord::Extensions inserts by including this optional parameter.
Finally, you create a flash notice with the number of uploaded records, the total
number of records, the total time elapsed, and the rate of records being processed per
minute.
flash[:notice] << " #{count} uploaded, #{Hit.count} total\n"
flash[:notice] << " #{'%0.2f' % real_time_elapsed} elapsed, " <<
"#{'%0.2f' % (count.to_f /
real_time_elapsed)*60
} records per minute ."
redirect_to :controller=>:home, :action=>:index
end
After creating the flash message, you redirect to the main page again. Note that you
could have created a separate view that displayed the message and then offered a link
back to the main page.
Pages:
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299