Juggernaut, du pushing sous Rails

19 Jan 2008

@line_buffer.sub!("\n", '') #gets around problem with JSON parsing client request
class ChatController < ApplicationController
    layout = "chat"
    def index
        session[:juggernaut_channels] = ["chat_channel"]
    end
    def send_data
        input_data = CGI.escapeHTML(params[:chat_input])
        data = "new Insertion.Top('chat_data', '<li>#{input_data}</li>');"
        Juggernaut.send_data(data, session[:juggernaut_channels])
        render :nothing => true
    end
end
<html>
    <head>
        <%= javascript_include_tag :defaults %>
        <%= listen_to_juggernaut_channels :chat_channel %>
    </head>
    <body>
        <%= form_remote_tag(:url => { :action => :send_data },:complete => "$('chat_input').value = ''" ) %>
        <%= text_field_tag( 'chat_input', '', { :size => 20, :id => 'chat_input'} ) %>
        <%= submit_tag "Add" %>
        </form>
        <ul id="chat_data" style="list-style:none">
        </ul>
    </body>
</html>