Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails 3 - Public live chat

I want to create a public live chat application using rails 3.

I found some example on rails 2. Any one can tell you a good example / tutorial to develop a live chat application using rails 3.

like image 696
Sayuj Avatar asked Aug 23 '11 05:08

Sayuj


2 Answers

I encountered several roadblocks as I tried to implement a public and private chat system in my rails 3 app. I looked at faye, juggernaut, node.js and more. Eventually after trying several approaches I was able to implement a system that works great:

1) I started by following the video guide to faye messaging in Railscast 260 as mentioned by Devin M. I was able to quickly setup a rails app that persisted messages, and a chat server that pushed these new messages out to all the clients. The biggest problem was security. I had no control over access to the chat server.

2) This lead me to using the private pub gem by Ryan Bates in Railscast 316 - which helps to secure your faye server by verifying the client's signature. This worked for securing the server but I ran into issues trying to verify the actual user with my authentication system and adding 'who's online' functionality. I worked on a hack of private pub to pass in the user details when authenticating but could not get things to work smoothly.

3) In the end I decided to move the chat server to pusher - a hosted API for real-time apps. I followed this tutorial on how to create a real-time survey in rails to get a feel for how to set things up. Although not directly about setting up a chat system - this tutorial along with what I had already setup from the Railscasts above (and the easy-to-read pusher docs), allowed me to quickly setup a secure rails 3 chat app - complete with authentication, 'who's online', status messages and more. The best part is...I don't have to deal with managing the chat server.

Hope this helps someone going through the same process as me.

like image 177
yellowaj Avatar answered Oct 12 '22 01:10

yellowaj


You can get the basics down with Railscast 260, I assume a background in Rails/Ruby already and some knowedge of jQuery/JavaScript. The screencast has a text version here and the source is here, it's also on GitHub.

like image 35
Devin M Avatar answered Oct 12 '22 03:10

Devin M