title: How to fix "Could not execute command from ({"command"=>"subscribe", "identifier"=>"{\"channel\":\"ConversationChannel\"}"}) "
body: <p>I'm trying to get user to connect user to conversation_channel and I receive:</p>
  
  <pre><code>Could not execute command from ({"command"=&gt;"subscribe", "identifier"=&gt;"  {\"channel\":\"ConversationChannel\"}"}) [NoMethodError - undefined method `id' for nil:NilClass]: /mnt/c/rails_apps/Picnotes/app/channels/conversation_channel.rb:6:in `subscribed' |
  </code></pre>
  
  <p>I tried hardcoding current_user.id to 1 or 2 and I got:</p>
  
  <pre><code>Started GET "/cable" for 127.0.0.1 at 2019-01-22 22:06:36 -0800
  Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2019-01-22 22:06:36 -0800
  Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
  ConversationChannel is transmitting the subscription confirmation
  ConversationChannel is streaming from conversations-1
  </code></pre>
  
  <p>My code is below:</p>
  
  <pre><code># Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
  class ConversationChannel &lt; ApplicationCable::Channel
    # Create a unique channel for each user.
  ...
    def subscribed
      stream_from "conversations-#{current_user.id}"
    end
  
    # Removes all connected connections.
    def unsubscribed
      stop_all_streams
    end
  ...
  
    end
  end    
  
  module ApplicationCable
    class Connection &lt; ActionCable::Connection::Base
      identified_by :current_user
  
      def connect
        self.current_user = current_user
      end
    end
  end
  
  class ApplicationController &lt; ActionController::Base
    protect_from_forgery with: :exception
    before_action :initiate_instance_variables
  
   ...
  
    def current_user
      @current_user ||= User.find_by(id: session[:user_id])
    end
  
    helper_method :current_user
  
    ...
  
  end
  </code></pre>
  
  <p>I expect <code>#{current_user.id}</code> to be the user id (constant: 1 or 2), but the object is always nil.</p>