【发布时间】:2021-03-26 15:45:54
【问题描述】:
我正在构建一个代码应用程序,它会根据每 60 秒刷新一次的数据提醒用户。我不希望来自客户端的新数据调用,但不知道如何让控制器不断进行其 API 调用并推送到客户端。
def search
@price = find_price()
render json: @price
end
private
# Use callbacks to share common setup or constraints between actions.
# def setprice
# @price = Price.find(params[:id])
# end
def request_api()
response = Excon.get(
'example.api'
)
return nil if response.status != 200
data = JSON.parse(response.body)
data['PriceRange']['4']
end
def find_price()
request_api()
end
# Only allow a trusted parameter "white list" through.
def price_params
params.require(:price).permit(:price)
end
end
【问题讨论】:
标签: ruby-on-rails server-sent-events actioncable