向控制器发送每个请求的长轮询实施

以下是实现长轮询的代码。向控制器发送每个请求的长轮询实施

class ApplicationController < ActionController::Base 

# Prevent CSRF attacks by raising an exception.

# For APIs, you may want to use :null_session instead.

protect_from_forgery with: :exception

cattr_accessor :acArray

end

ApplicationController.acArray = []

class HelloController < ApplicationController

def initialize

ApplicationController.acArray << self

end

def index

ApplicationController.acArray.each_with_index {|val, index|

if index == 1 # only on second request serve the first request, until then hold the object in memory

val.render :text => ApplicationController.acArray.length

end

}

end

end

的问题是所述第一请求被与所述消息

模板丢失 缺失模板你好/索引,应用程序/索引含{立即失败:区域设置=> [:EN]:格式= > [:html],:handlers => [:erb,:builder,:raw,:ruby,:jbuilder,:coffee]}。搜查:*“/家/ MYHOME的/ tmp /聊天/应用/视图”

如何延迟渲染,而不是让轨道搜索视图文件,而不是返回失败状态

回答:

也许这将工作:

until ApplicationController.acArray.length > 1 do |process| 

end

ApplicationController.acArray.each_with_index{|val, index|

if index == 1

val.render :text => ApplicationController.acArray.length

end

}

`

以上是 向控制器发送每个请求的长轮询实施 的全部内容, 来源链接: utcz.com/qa/261467.html

回到顶部