我想这样做:
In the view, have a button_to "Find"
The button click submits the search query to the rails action (controller)
The action calls some external api
A response comes back in 1ms up to 20secs (who knows? it's an external webservice, right?)
When the response is returned, the view which originally contains the button_to and the search field is updated with the response (via javascript)
由于
答案 0 :(得分:1)
当您想要更改发出请求的页面时,您的按钮将触发AJAX调用。在服务器端,您只需使用类似HTTParty的lib来拨打电话,等待响应服务器,根据需要进行处理,然后自行发送响应。
AFAIK此操作没有具体名称;但是我们可以说你的服务器充当另一个服务的代理,如果你从许多不同的API重新处理答案,那么你的服务就是一种聚合器 < / p>
要更新视图,具体取决于您实施ajax调用的方式。你可以:
回复一些JS,通常是一个会在客户端执行的代码片段,如
$('#my_element')。replaceWith('&lt;%= j(render partial:“some_partial”)%&gt;');