首先是配置的问题
APP_SETTINGS[:orbited_host] = 'localhost'
APP_SETTINGS[:orbited_port] = '8500'
APP_SETTINGS[:site_address] = 'localhost:3000'这里localhost改成你的IP吧,这样你想在局域网页测试的话就可以试
其次是controller
require 'stomp'
class ChatController < ApplicationController
def send_data
unless params[:chat_input].empty?
javascript = render_to_string :update do |page|
page.insert_html :top, 'chat_data', "MESSAGE: #{h params[:chat_input]}"
page[:chat_input].clear
page[:chat_input].focus
s = Stomp::Client.new
s.send(params[:channel],javascript)
s.close
end
end
render :nothing => true
end
end
以我有限的知识这个怎么看都不像是对的,在javascript = xxxx 的block里面还用
s.send(params[:channel], javascript)
所以把 s = Stomp::Client.new
s.send(params[:channel],javascript)
s.close
移到render_to_string外面 就行了
总的来说用Rails + Orbited效果相当满意,挺不错的
共同學(xué)習(xí),寫下你的評(píng)論
評(píng)論加載中...
作者其他優(yōu)質(zhì)文章