6

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.

Sayuj
  • 7,464
  • 13
  • 59
  • 76

3 Answers3

7

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.

yellowaj
  • 465
  • 5
  • 10
  • Does pusher also saves(Archive) sent messages, so that I can retrieve previous messages when User logins on a new device. For example I can query and retrieve messages of past two days, 1 week or month for a specific user or group. – Muhammad Nabeel Arif Apr 03 '13 at 11:28
  • 1
    @MuhammadNabeelArif - I don't believe their current API offers that feature (but I may be mistaken). To achieve the same results I just saved the messages in the db and then deleted older messages after 2 days. – yellowaj Apr 03 '13 at 16:58
  • Could you please give some details on the "issues trying to verify the actual user with my authentication system"? What kind of authentication system and does it matter or there are issues with any auth system? I'd like to know about integrating the LDAP (Active Directory) into it. – dimir Nov 10 '13 at 21:32
6

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.

Devin M
  • 9,636
  • 2
  • 33
  • 46
3

I'd start by checking out Ilya Grigorik's em-synchony + examples and looking at the code for the Hector private chat server gem.

Alec Wenzowski
  • 3,878
  • 3
  • 25
  • 40