3
서버를 다시로드하지 않고도 데이터베이스의 변경 사항을 페이지에 반영하고 싶습니다.ActionController :: Live - SSE in Rails
컨트롤러
class ProductController < ApplicationController
include ActionController::Live
def index
@product = Product.available
response.headers['Content-Type'] = 'text/event-stream'
sse = SSE.new(response.stream)
sse.write @product
ensure
sse.close
end
end
보기 나는 퓨마를 사용하고
<p><%= @product[:price] %></p>
.
데이터베이스에서 제품을 업데이트 할 때 변경 사항이 웹 페이지에 반영되지 않습니다.
무엇이 누락 되었습니까?
Redis는 현재 내 스택에는 없습니다. 이 기능을 작동시키기 위해 특별히 설정해야 할 부분이 있습니까? @KPheasey – softcode
샤워가 생성되는 것처럼 보입니다. 경로 --- get '/ stream', : 'shower/stream # index'--- 스트림이/stream으로 스트리밍 되었습니까? 그렇다면 페이지 방문시 Rails에서 "고정 된 해시를 수정할 수 없습니다"@KPheasey – softcode