Track all online users in Volt

I am trying to record all the users who are currently online.

Here is what I tried:

  • In my "main_controller":

    channel.on ('connect') {puts "ON"; store._online_users <Volt.current_user.to_h} channel.on ('disconnect') {puts "OFF"; store._online_users.delete (Volt.current_user.to_h)}

In my "main.html":

  {{store._online_users.each do |user| }}
    {{user.to_h}} <br>
  {{end}}

The problem is that at some point when I tested this, I got about a dozen entries in the list store._online_users. I want to delete them all, but I cannot get it to work. I tried:

  • store._online_users.clear has no effect
  • store._online_users.each(&:destroy) no effect
  • store._online_users = [] no effect

Edit

, , , Volt.current_user - , - auth.

store._online_users , .

, store._current_users :

  channel.on('connect') {
    Volt.current_user.then { |user|
      unless user.nil?
        store._current_users << user
      end
    }
  }
  channel.on('disconnect') {
    Volt.current_user.then { |user|
      unless user.nil?
        store._current_users.delete(user)
      end
    }
  }

ModelArray, -?

+4

All Articles