Class: ModelUpdates::CreateChannel

Inherits:
ApplicationCable::Channel
  • Object
show all
Defined in:
app/channels/model_updates/create_channel.rb

Instance Method Summary collapse

Instance Method Details

#subscribedObject



2
3
4
5
6
7
8
9
10
11
# File 'app/channels/model_updates/create_channel.rb', line 2

def subscribed
  model_class = params[:model].safe_constantize
  channel_name = "ModelUpdatesCreate#{params[:model]}"

  stream_from(channel_name, coder: ActiveSupport::JSON) do |data|
    model = model_class.accessible_by(current_ability).find(data.fetch("id"))
    next unless model
    transmit data
  end
end