考虑以下情况:
1) WebSocket验证连接.
def connect
self.current_user = find_verified_user
logger.add_tags "ActionCable", "User #{current_user.id}"
end( 2)当建立连接时,通知用户
connected: ->
$("body").append("<div class='connection ok'>Connected.</div>")3)当连接丢失时,通知用户
disconnected: ->
$("pop-up").append("<div class='connection'>Offline, trying to reconnect...</div>")4)当用户注销时.
An unauthorized connection attempt was rejected
###User is now informed connection is lost. Which should not happen.我的问题:如何更改:
mount ActionCable.server => '/cable'若要仅在的范围内运行,请执行以下操作:
authenticated :user do
root 'users#index', as: :authenticated_root
end发布于 2017-07-11 13:06:16
替代解
未经授权的连接尝试被拒绝。
...happens,当reject_unauthorized_connection在connection.rb中被调用时。
- remove `reject_unauthorized_connection` if you want to allow non-signed-users to subscribe to the channel: `current_user` becomes `nil` - To be able to still identify the user, you can add another identifier (`:session_id`) : 模块ApplicationCable类连接< ActionCable:: Connection ::Base identified_by :current_user identified_by :session_id def self.current_user = find_verified_user self.session_id = request.session.id end私有def find_verified_user User.find_by(id: cookies.signed:user_id) end #.
-如果您需要客人和登录用户之间的进一步授权规则,您可能希望在您的*_channel.rb中而不是在connection.rb中写入您自己的授权。
- retain `reject_unauthorized_connection` if you only want signed-in users to be able to subscribe to your channels.
https://stackoverflow.com/questions/45021756
复制相似问题