1

I have a csv file (@fn) with close to 100,000 records (about 50 megs) that I am inserting into a mysql table. For example:

FCSV.foreach(@fn, {:headers => true}) do |row|
    model = Model.new(Hash[row])
    model.save
end

Back in my ASP days, I could output and print the buffer as html to the users screen durring this loop so as to provide a visual feedback as to how far along the process was. In ruby on rails, is there an equivalent of this approach?

If it helps, I'm using Rails 2.3.9 and Ruby 1.8.7.

I realize there are a dozen ways to accomplish the feedback, such as background jobs, etc. But what I am really wondering about is how to dump and print the buffer to the screen (not the console) with each iteration of the loop.

iamtoc
  • 1,569
  • 4
  • 17
  • 24

1 Answers1

0

This question might be of some help to you. It explains how to stream using the older rails client.

Ruby on Rails 3: Streaming data through Rails to client

Here is the example directly from the post:

render :text => proc { |response, output|
  10_000_000.times do |i|
    output.write("This is line #{i}\n")
  end
}
Community
  • 1
  • 1
sunnyrjuneja
  • 6,033
  • 2
  • 32
  • 51
  • I can see the output in my debugger when I use print("This is line #{j}\n") but nothing dumps to the browser with output.write("This is line #{j}\n"). – iamtoc Oct 11 '12 at 06:54
  • I haven't worked at all with Rails ~2 and all the documentation I found line was for Rails ~3. I'm not sure exactly what's wrong, sorry. – sunnyrjuneja Oct 11 '12 at 07:05