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 effectstore._online_users.each(&:destroy)
no effectstore._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?