Skip to content

A simple xmpp publish hook to make your rails app real-time.

Notifications You must be signed in to change notification settings

thepug/railsrealtimedemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a demo rails application to show how to have your rails app
post to an xmpp pubsub node.

What you will need:

ejabberd
A good tutorial on how to setup ejabberd, 
http://metajack.im/2010/02/04/screencast-setting-up-ejabberd/

rails3
xmpp4r

strophejs
Can be found at http://code.stanziq.com/strophe
Download strophejs, run make

tape
Can be found at http://github.com/metajack/tape

Quickstart:
Install the above dependencies.
git clone http://github.com/thepug/railsrealtimedemo
cd railsrealtimedemo
rake db:migrate
rails s
open a new shell
cd railsrealtimedemo/public
tape -P /http-bind=http://localhost:5280/http-bind
open a new shell
cd lib
edit config.yml and change username and password to your xmpp user
go to http://localhost:8273 and login with the user
go to http://localhost:3000/posts and ad a new post
If you go back to http://localhost:8273 you will see the resulting post in xml

Details: 
Install dependencies at the beginning of this readme.

The project at http://github.com/thepug/railsrealtimedemo is the
simple blog post demo that everyone uses. The difference is the post
model contains a hook that publishes the xml version of the model to a
pubsub node.

require 'xmpp_publish'
class Post < ActiveRecord::Base
  after_save { 
    begin
      publish(self.to_xml) 
    rescue Exception=> e
      logger.info(e)
    end
  }
end

The xmpp_publish module is in the lib directory.  It contains the
xmpp4r code to publish to a pubsub node.  You can also use the script
lib/test_createnode.rb to create your pubsub node.

When you make a change or create a Post the new info will be published
to your node.  An example javascript program is included to demo the
xml that is published.

The javascript program uses strophe and the strophe pubsub plugin to
subscribe to your node and display the xml it recieves. See
public/javascripts/basic.js and public/index.html for the demo code.


About

A simple xmpp publish hook to make your rails app real-time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published