【发布时间】:2014-02-03 12:16:50
【问题描述】:
下面是实现长轮询的代码。
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
问题是第一个请求立即失败并显示消息
模板丢失 缺少模板 hello/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :咖啡]}。搜索:*“/home/myhome/tmp/chat/app/views”
如何延迟渲染不让rails搜索视图文件不返回失败状态
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4