Ruby on rails Rails web套接字-授权
我有Ember.js客户端和带有GemWebSocket rails的RoR服务器端 我需要获得只有一个用户才能发送消息的授权的私有通道 我就是这样尝试的:Ruby on rails Rails web套接字-授权,ruby-on-rails,ruby,sockets,ember.js,authorization,Ruby On Rails,Ruby,Sockets,Ember.js,Authorization,我有Ember.js客户端和带有GemWebSocket rails的RoR服务器端 我需要获得只有一个用户才能发送消息的授权的私有通道 我就是这样尝试的: class AuthorizationController < WebsocketRails::BaseController before_action :require_login def authorize_channels # The channel name will be passed i
class AuthorizationController < WebsocketRails::BaseController
before_action :require_login
def authorize_channels
# The channel name will be passed inside the message Hash
puts '*'*400
ap current_user//Here I see the user
channel = WebsocketRails[message[:channel]]
accept_channel current_user
end
def require_login
sign_in(User.find(4))
end
end
但当我尝试使用以下内容发送消息时:
WebsocketRails.users[4].trigger(:test_event, { message: 'This is a private message from WebSocket Rails' } )
我得到错误如果你使用rails api gem,它会禁用会话,这就是问题所在。似乎没有建立连接,你如何建立它?我使用gem,这是因为我在调试器中看到连接,并且可以使用公共通道发送事件
WebsocketRails.users[4].trigger(:test_event, { message: 'This is a private message from WebSocket Rails' } )
#<WebsocketRails::UserManager:0x007ff5bb617d68 @users={}>