I am trying to implement Action Cable
. I have previously worked with it though only the basics. I am now working on a project where the admin and the client section are two different projects. The database for both is same of-course.
What i want is that as soon as the User
(from the Client-Side Project
) texts the admin, it should (text) be displayed to the Admin
(In the Admin side Project
) in real time, i.e without refreshing the page.
How to use ActionCable as API gave me ideas but i'm not sure as how i should move forward with it.
Another idea that i had was to implement action cable
in the Admin
Project and call it in a action
of a controller
. Now when the text is created in the client
project, i'll call this action (in the controller of admin project; how i have not yet figured out and yet working on it). This way the Action Cable
will reflect changes in the Admin
.
I don't know if this approach is correct or there's another way.
I'll be grateful for any guidance. Thanks.
P.S: Let me know if this confusing and messy. I'll give it another try.
All you should need is to have the admin user subscribe to a channel only used by admins and at the same time have the messages being submitted by users broadcast to that specific channel.
Something along the lines of this:
channels/admin_chat_channel.rb
I'm using coffeescript in this example. I can convert it to js if you prefer.
javascripts/channels/admin_chat.coffee
On the controller in which you will be receiving the submitted messages you just need to broadcast the message: