4

I'm trying to make a record of all the users which are currently online.

Here's what I've 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, at some point when testing this I ended up with around a dozen entries in the store._online_users list. I want to delete them all, but I can't get it to work. I've tried:

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

Edit

So, since originally posting this question, I've realized that Volt.current_user is nil unless somebody has logged in through the auth system.

There's still the problem of undeletable records in my store._online_users, so I'm trying a different key.

I tried the following, but store._current_users always remains empty:

  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
    }
  }

How would i make a ModelArray which contains all currently online users?

max pleaner
  • 26,189
  • 9
  • 66
  • 118
  • What does your store model look like? – Ronna Apr 06 '16 at 13:20
  • 1
    I see a possible mixup of _online_users and _current_users, which association are you using? Could this be the problem? – Ronna Apr 06 '16 at 13:23
  • @Ronna I started trying to use `online_users`. But then I ended up with a bunch of records in there that I didn't know how to delete. That's when I switched to `current_users`. By the way, `store` is not a model, it is a built in keyword in Volt. – max pleaner Apr 06 '16 at 17:49
  • 1
    I found this test in their code base, they expect it to fail, but I didn't find the corresponding issue to confirm it's just buggy - https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/spec/integration/first_last_spec.rb – Ronna Apr 07 '16 at 11:21

0 Answers0