我有一个使用 react 作为前端的 Rails 应用程序。从我的 Rails 控制器中,我正在调用基于浏览器的 api。通过 Watir 和控制器内部的一些“放置”,我可以在终端内获取呼叫状态。例如,在我的终端中,我会看到“Loading 1%...”“Loading 10%”等...直到完成。我想要做的是向我的前端应用程序显示这个值。对 Rails 很陌生,不知道从哪里开始。为了点击 call_api(username) 方法,我从前端的按钮进行 Ajax 调用。到目前为止,一切都运行良好。我唯一想补充的是我在客户端的通话状态。
我曾尝试使用 gem gon,但问题是我的整个应用程序是基于我的根路由“/”所以如果例如我的 index 方法是这样的,而我的 call_api 方法是这样的
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
当我进入浏览器控制台并尝试 console.log(gon.status) 时,我仍然得到“started”的值,因为我的应用程序仍在索引路由上。可能有更好的方法。非常感谢任何有关如何进行的帮助和建议。谢谢