【发布时间】:2016-10-01 12:03:51
【问题描述】:
我正在尝试使用 Rails 5 中的操作电缆实现通知。
在阅读了 Action 电缆的教程后,该电缆使用基于会话和 Cookie 的身份验证来接收当前登录用户的通知。
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user.username
end
protected
def find_verified_user
if verified_user = env['warden'].session(:user)
verified_user
else
reject_unauthorized_connection
end
end
end
在 find_verified_user 中,我无法从会话中获取用户对象。
任何人都可以帮助我,在行动电缆中对用户进行身份验证。
【问题讨论】:
-
不要将会话用于 ActionCable,请参阅此答案:stackoverflow.com/questions/32025897/…
标签: ruby websocket notifications ruby-on-rails-5 actioncable