Streaming a .js.erb response

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Streaming a .js.erb response



In this scenario, when the user submits his form,
the $("body .my-flash-div") div should first show


$("body .my-flash-div")


Generating report



then after a few seconds


Sql executing



so on and so forth.



My issue is that the end user is shown the results at once, and not in a step by step manner. Here's my setup:


End users want to download reports
Report generation is a multi step process, takes 5-10 seconds.
Step 1 user does GET /users_report/new
There's a form there, user enters email address, submits
And it's handled by

class UsersReportController < ApplicationController
def create
respond_to do |format|
format.js
end
end


# app/views/users_report/create.js.erb
$("body .my-flash-div").html("Generating report");
<% Namespace::gen_report_step_1 %>
<% sleep 1 %>
$("body .my-flash-div").html("Sql executing");
<% Namespace::gen_report_step_2 %>
<% sleep 1 %>
$("body .my-flash-div").html("Post processing");
<% Namespace::gen_report_step_3 %>
<% sleep 1 %>
$("body .my-flash-div").html("gzip execute");
<% Namespace::gen_report_step_4 %>
<% sleep 1 %>
$("body .my-flash-div").html("Emailing "+params[:email]);



Can can I make this work, or should I look at actionable for this, if so how.





You can use window.setTimeout or jQuery.delay
– max
34 mins ago





I added some sleep 1 calls to illustrate why setTimeout and .delay might not be appropriate
– american-ninja-warrior
12 mins ago





Yeah if you want to perform a bunch of tasks that might take time and have the client subscribe for updates you´ll want to use ActionCable. Otherwise the response is sent once the view is rendered in entirety.
– max
9 mins ago





can ActionCable::Live be used?
– american-ninja-warrior
3 mins ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

C# - How to create a semi transparent or blurred backcolor on windows form

Will Oldham

Makefile test if variable is not empty