Reputation: 21
I have a rails app set up with react as front end. From my rails controller I am making a call to a browser based api. Through Watir and some "puts" inside my controller I can get the status of my call inside the terminal. For example in my terminal I will see "Loading 1%..." "Loading 10%" etc... until it is done. What I am trying to do is to show this value to my front end app. Quite new to rails and not sure where to begin. In order to hit the call_api(username) method I am making a Ajax call from a button on my front-end. So far everything is working good. The only thing I would like to add is the status of my call on the client side.
I have tried using the gem gon but the problem is that my whole app is based on my root route "/" so if for example my index method is like this and my call_api method is like this
def index
@status = "started"
gon.watch.status = @status
end
def call_api(username)
@status = "new value for test"
gon.watch.status = @status
until @status == "Finished"
@status = @browser.span(class: "monoFont").text
puts "status" + @status
sleep 1
end
end
When I go inside my browser console and I try to console.log(gon.status) I still get the value of "started" as my app is still on the index route. Probably there is a better way. Any help and recommendation on how to proceed is greatly appreciated. Thank you
Upvotes: 1
Views: 252
Reputation: 3339
If I'm not wrong you need a status updating continuously in your view while the API is doing some scraping on the web. So I think you may need web socketing or something like that because your API is continuously running and you need a real-time update in your view. Take a look at web socketing.
Upvotes: -1