my channel:
class DevicesChannel < ApplicationCable::Channel
def subscribed
stream_from 'datas_channel', coder: ActiveSupport::JSON
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
raise NotImplementedError
end
def receive
data = DeviceInformation.create(message: "oks")
ActionCable.server.broadcast("datas_channel", data)
end
end
To send request for subscribe, did:
{
"command": "subscribe",
"identifier": "{\"channel\":\"DevicesChannel\"}"
}
And, to write message:
{
"command": "message",
"identifier": "{\"channel\":\"DevicesChannel\"}",
"data": "{\"message\":\"Hello world\", \"action\": \"receive\"}"
}
On above request, it works well. it call receive method and works well.
But i want to call controller action 'Create' i.e
class DeviceInformationsController < ApplicationController
def create
data = DeviceInformation.create(message: 'Hello world')
ActionCable.server.broadcast("datas_channel", data)
end
end
is it possible to do? any help would be really appreciated. I am new to web socket API