Ask A Question

Notifications

You’re not receiving notifications from this thread.

Group Chat with ActionCable: Part 2 Discussion

Hi Chris,
Is it possible to make a REST API for this app and create a Mobile app using Jquery mobile or Android and do real time chat with people chatting on desktop?
I have an application with Rails 5, Action Cable and Devise. I am planning to create mobile app to let mobile users do realtime chat with users on desktop or any other device. My website is device responsive but I am wondering if we can create a mobile app with REST API and do real time chat with Action Cable? Or is Action Cable only applicable to desktop users?

Reply

Basecamp uses Turbolinks and the ActionCable JS on mobile to power their app, however I'm sure you could port the client over to a native Swift or Obj-C client that would allow you to build a native app. It'll probably be a decent amount of work to start, but this is an example of someone who build an ActionCable client in Ruby (rather than the default JS) so you could probably use it as a basis for building a Swift client.

If you just go with Turbolinks views on mobile, you'll have a really easy time making this all work because the mobile UI will be the exact same code you use on the desktop browser.

Reply

If you want to develop a native iOS app, you can use a Swift client like this: https://github.com/NullVoxP...

Reply
loveisnuclear loveisnuclear

Hi, When I try to leave the second (and last) chatroom I joined, I get this error instead of returning me to the chatroom path: https://uploads.disquscdn.c...

My routes look fine to me (when comparing to the source code), so i'm not sure why it isn't working.

Reply
loveisnuclear loveisnuclear

Nevermind, `chatrooms_path` shouldn't have the `@` before it! I hope this helps someone else coming across this.

Reply

@excid3:disqus awesome tutorial series!

You've said around 6:15 it would be good to add indices to the chatroom_users table. I just can't figure out of to add an uniq index for the chatroom and user references. Do you got a tip for that?

Reply

You would want something like this:

add_index(:chatroom_users, [:chatroom_id, :user_id], unique: true)

Reply

@excid3:disqus

Hi Chris, can you explain again what the "before_action :set_chatroom" in the ChatroomUsers controller does? Does it just point all the join and leave methods to the specific chatroom id?

Thanks!

Reply

Because this controller is used to manage who is actually subscribed to a chatroom, we always include the chatroom ID in the URL. Then we just look up the chatroom and permanently add or remove the join table records to denote who is in the room or not. So yes, basically what you were saying. It's auto-scoping the actions its taking by the chatroom ID in the URL.

https://github.com/gorails-...

Reply
Jon Holstead Jon Holstead

I have implemented this system in my own project. A problem I have is that I do not know when to destroy_all users (as you have done) when the user closes the website for example. How can I detect if they have left the site, and therefore their record in ChatroomUsers needs to be destroyed? I am using this also to show how many active users are in the chatroom, and the number does not go down when the user leaves by closing their browser because of this. Thanks.

Reply

Hi, I've really been enjoying the tutorial! I've been trying to implement this with rails 5.2.5 but I've had little to no luck getting it working. Is there anyone here that has got it working on this version?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.