# Outputting to webpage the lines of a file or array as each line is processed.. eg ob\_flush() for Ru

**URL:** <https://www.ruby-forum.com/t/outputting-to-webpage-the-lines-of-a-file-or-array-as-each-line-is-processed-eg-ob-flush-for-ru/142809>\
**Category:** Rails\
**Created:** [July 11, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/outputting-to-webpage-the-lines-of-a-file-or-array-as-each-line-is-processed-eg-ob-flush-for-ru/142809 "2008-07-11T19:00:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamietssg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@jamietssg](https://www.ruby-forum.com/u/jamietssg)\
**Post date:** [July 11, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/outputting-to-webpage-the-lines-of-a-file-or-array-as-each-line-is-processed-eg-ob-flush-for-ru/142809/1 "2008-07-11T19:00:25Z")

</div>

Hello all,

I have some code that reads and works on each row of an array. Is it  
possible for Ruby on Rails to to display in a view/webpage each row as  
it is processed.

The idea is that I want the user of the app to see the progress that  
the app is making as the action runs.  
EG the user sees the following appear as the rails action runs…

“row 1 is processed…”

then as row 2 is processed

“row 1 is processed…  
row 2 is processed…”

etc etc

I believe this is achieved in PHP by flushing the output buffer…  
Can this be achieved with rails?

Thanks in advance!! 🙂  
Jamie

---

<div class="post-metadata">

**Author:** ![jamietssg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@jamietssg](https://www.ruby-forum.com/u/jamietssg)\
**Post date:** [July 11, 2008, 9:17pm UTC](https://www.ruby-forum.com/t/outputting-to-webpage-the-lines-of-a-file-or-array-as-each-line-is-processed-eg-ob-flush-for-ru/142809/2 "2008-07-11T21:17:26Z")

</div>

Hi Jamie,

jamietssg wrote:

> “row 1 is processed…”
> 
> then as row 2 is processed
> 
> “row 1 is processed…  
> row 2 is processed…”
> 
> etc etc

Rails runs in a pretty strict request - response cycle. Each request  
fires  
up an instance of Rails which constructs and returns a response. One  
response per request. What you’re describing can be accomplished in a  
couple of ways (at least), but unless the row processing takes a  
substantial  
amount of time (per row) you may not find either worth your while.  
Having  
said that …

One way to handle this would be to utilize background processing via  
BackgrounDRb. You’d feed it the array and query it periodically from  
the  
client to get status.

Another way would be to set up the processing so that the client  
actually  
requests processing of one line, the server responds with status when  
that’s  
complete, the response triggers some JS function which issues a new  
request  
to the server to process the next entry in the array, etc.

BackgrounDRb is, IMHO, probably the easier way to go from a programming  
perspective but, depending on your production support, you may not want  
/ be  
able to support distributed processing.

HTH,  
Bill
