Need help with juggernaut_plugin?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

196 Stars 23 Forks MIT License 34 Commits 0 Opened issues


Realtime Rails

Services available


Need anything else?

Contributors list

# 37,646
26 commits
# 556
2 commits
# 51,476
1 commit
# 71,789
1 commit
# 674,686
1 commit
# 352,726
1 commit


This repo has now been deprecated - please see:



Author: Alex MacCaw E-Mail Address: [email protected] License: MIT Website: Blog:


The Juggernaut plugin for Ruby on Rails aims to revolutionize your Rails app by letting the server initiate a connection and push data to the client. In other words your app can have a real time connection to the server with the advantage of instant updates. Although the obvious use of this is for chat, the most exciting prospect for me is collaborative cms and wikis.

What Happens:

  1. Client A opens socket connection to the socket server
  2. Client B makes Ajax call to Rails
  3. Rails sends message to the socket server
  4. Socket server broadcasts message to clients

Juggernaut Features:

* Allows a real time connection with a client - Rails can literally push javascript in real time to the client which is then evaluated.
* Push server - written in Ruby.
* Integrated, as a plugin, into Rails.
* Subscribers can subscribe to multiple channels, and broadcasters can broadcast to multiple channels.
* Subscribers can provide a 'unique_id' and broadcasters can send data to specific clients.
* Add and remove channels at runtime
* Uses Flash 8 - installed on more than 98% of computers.
* Supports all the major browsers (uses ExternalInterface): Firefox 1+, IE 6+ and Safari 2+.


* Rails 2.0.2 or edge
* json gem (gem install json)
* EventMachine gem (gem install eventmachine)
* juggernaut gem (gem install juggernaut)



  1. From your Rails Dir: script/plugin install git://
  2. Make sure to include the appropriate JavaScripts in your views/layouts in the header of your views <%= javascriptincludetag 'prototype', :juggernaut %>
  3. Add this to your view/layout head: <%= juggernaut %>
  4. Make sure the juggernaut gem is installed (gem install maccman-juggernaut -s ) and run: juggernaut -g juggernaut.yml juggernaut -c juggernaut.yml
  5. Run script/server and visit the Jugged up page.
  6. Then, to send data to juggernaut, execute this in the console: Juggernaut.sendtoall("alert('hi from juggernaut')")


To demonstrate Juggernaut I'll walk you through building a simple chat.

Start the push server going by running: juggernaut -g juggernaut.yml juggernaut -c juggernaut.yml

The chat controller:

class ChatController < ApplicationController def index end

def senddata render :juggernaut do |page| page.inserthtml :top, 'chatdata', "

  • #{h params[:chat
  • input]}" end render :nothing => true end end

    The index.html.erb

     { :action =&gt; :send_data },
          :complete =&gt; "$('chat_input').value = ''" ) %&gt;
       20, :id =&gt; 'chat_input'} ) %&gt;
    </pre><ul id="chat_data" style="list-style:none">

    Start the webserver going with: ruby script/server

    Try it and see what you think. If it doesn't work please visit the faq.

    Other ways of rendering to juggernaut:

    render :juggernaut do |page| page.alert('hi') end

    render_juggernaut(:action => 'whatever')


    More usage information, examples and support

    === Channel Usage ===

    <%= juggernaut(:channels => ['one', 'two', 'three']) %> render :juggernaut => {:type => :sendtochannels, :channels => ['one']} do |page| page.alert('hi') end

    Client id usage: <%= juggernaut(:clientid => session[:userid]) %> render :juggernaut => {:type => :sendtoclients, :client_ids => [1, 2, 3]} do |page| page.alert('hi') end

    Other juggernaut render options: OPTIONTYPE PARAMS :sendtoall
    tochannels :channels :sendtochannel :channel :sendtoclient :clientid :sendtoclients :clientids :sendtoclientonchannel :clientid, :channel :sendtoclientsonchannel :clientids, :channel :sendtoclientonchannels :clientid, :channels :sendtoclientsonchannels :client_ids, :channels

    You can also call these methods directly on the Juggernaut class: Juggernaut.sendtoclients('data', [1,2,3])

    For authentication options and callbacks see the juggernaut.yml configuration file.

    Usage and examples: Support and forums:

    === Getting remote clients to connect ===

    Firstly you will need to configure juggernaut_hosts.yml in your Rails app to point to the proper IP of the push server (rather than For example: :hosts: - :port: 5001 :host: :environment: :production

    Ok, remote clients that visit pages on this server (once you restart it) will connect to the proper push server IP. BUT, if you're using IP based authentication (recommended) you'll find that the broadcast authentication fails. You'll need to add the Rails IP to juggernaut.yml, like so:

    :allowed_ips: - - # IP of the Rails app



    To get Juggernaut working with Jquery (Prototype is used by default) follow the tutorial above with the following differences.


    You must have jquery.js (version 1.2.6 tested) and the jquery-json plugin ( in the /javascripts directory.

    You need the jquerynaut.js file in the /javascripts/juggernaut directory (found in /lib in the media directory)

    The chat controller:

    class ChatController < ApplicationController def index end

    def send_data
      render :juggernaut do |page|
        page["#chat_data"].prepend "
  • #{h params[:chat_input]}
  • " end render :nothing => true end


    The index.html.erb

    <%= javascriptincludetag 'jquery', 'json', 'juggernaut/juggernaut', 'juggernaut/jquerynaut', 'juggernaut/swfobject' %> <%= juggernaut %>
      <form action="/chat/send_data" method="get">
        <div style="margin:0;padding:0">
        <input id="chat_input" name="chat_input" size="20" type="text" value="">
        <input name="commit" type="submit" value="Add">



      Check out the support forums on google groups:

      We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.