Ruby on rails のaction cableを用いて、ルームチャットシステムを構築しようとしています。見様見真似でコードを書いているため、理解が追いつかずエラーが発生してしまいました。
app/channels/application_cable/connection.rb
rails5
1module ApplicationCable 2 class Connection < ActionCable::Connection::Base 3 identified_by :current_user 4 def connect 5 self.current_user = find_verified_user 6 end 7 8 private 9 def find_verified_user 10 verified_user = User.find_by(id: cookies.signed[:user_id]) 11 if verified_user && cookies.signed['user.expires_at'] > Time.now 12 verified_user 13 else 14 reject_unauthorized_connection 15 end 16 end 17 end 18end 19
エラー
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT",1]] ↳ app/channels/application_cable/connection.rb:10 There was an exception - NoMethodError(undefined method `>' for nil:NilClass)
cookies.permanent.signed[:user_id])
cookieが取得できてないってことですか?
なぜ取得できないのでしょうか?
どうすればcookieは利用可能になるのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/28 13:26
退会済みユーザー
2018/08/29 00:13