1
다음은 긴 폴링을 구현하는 코드입니다. = 형식 : 로케일 => [: EN],컨트롤러에 대한 모든 요청에 대한 긴 폴링 구현
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
문제는 첫 번째 요청이
템플릿 {와 누락 템플릿 안녕하세요/지수, 응용 프로그램/인덱스 누락 된 메시지와 함께 즉시 실패 도착하다 > [: html], : 핸들러 => [: erb, : 빌더, : 원시, : 루비, : jbuilder, : 커피]}. * "/ 홈/인 MyHome/tmp를/채팅/응용 프로그램/전망"
어떻게 렌더링을 지연시키고 레일 뷰 파일을 검색하고 어쩌면이 작동 실패 상태
동일한 오류를 반환합니다. 변경 없음 –
단지 궁금해서 오류가 발생하기 직전에 acArray 길이의 값을 인쇄 해 보았습니까? – rboling
** 오류가 발생하기 전에 1을 인쇄하는 else 블록에 ** p ** ApplicationController.acArray.length **를 ** 다음에 ** 넣습니다. –