count-anything/app/channels/count_channel.rb

41 lines
777 B
Ruby
Raw Normal View History

class CountChannel < ApplicationCable::Channel
def subscribed
stream_from "counts"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
def plus_one(params)
unless current_user.nil?
total = Total.find(params["id"])
unless total.nil?
total.update(count: total.count + 1)
end
end
end
def minus_one(params)
unless current_user.nil?
total = Total.find(params["id"])
unless total.nil?
total.update(count: total.count - 1)
end
end
end
def self.create(total)
end
def self.update(total)
ActionCable.server.broadcast("counts", {"update": total})
end
def self.destroy(total)
ActionCable.server.broadcast("counts", {"destroy": total.id})
end
end