开发者

Launching a rails helper method in background, then update the respective elements on the page using ajax

开发者 https://www.devze.com 2023-03-18 06:55 出处:网络
I have a webpage, which iterates through a list of sorts. For each of the items in the list, I need 开发者_StackOverflow社区to perform some computations, based on which I plot a graph.

I have a webpage, which iterates through a list of sorts. For each of the items in the list, I need 开发者_StackOverflow社区to perform some computations, based on which I plot a graph.

However, the computation takes itw own sweet time, and therefore I want to continue rendering the rest of the page, while the computations go on in the background.

From the requirements perspective, to me, it looks like ajax can help me achieve this background functionality piece, or can it not ?

When the functions return with their values, I want to bring in ajax into picture, and update the respective DIVs to populate the chart.

my points of confusion -

I am not dealing with controller/actions here. the action being rendered is index. and i get some list back. for that list i then launch this computation.

alternatively, i can plug this computation call in the index action itself, but then i'd have the challenge of not having the index action start rendering till all the computation is done.

Conceptually, I am pretty certain rails + ajax combo would allow me to achieve this. Just not getting my visualization through this.. any help ??


Would it be feasible for you to do the computation wholly independently from the index then access with ajax? You might miss a few ms of computation time but it might simplify things up for you.

Also, how often does this data need to be computed? Does it need to be done on every page load or can it be done daily/weekly/hourly or whatever? If it can, you can just do it in a cron job and just call the results via ajax or directly through the index.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号