No commit activity in last 3 years
No release in over 3 years
Very small and simple gem that makes using websockets really easy.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

SocketableRails¶ ↑

Playing with websockets and rails

Installation¶ ↑

Add to Gemfile

gem 'socketable-rails'

And

$ cd rails/app/path
$ bundle install
$ rake socketable:install
$ thin start

Usage¶ ↑

Building a realtime chat:

message.rb¶ ↑

Normal model

class Message < ActiveRecord::Base
  attr_accessible :content
end

home/index.html.erb¶ ↑

You need to add a :websocket => true parameter to your form

<%= form_for @message, :websocket => true do |f| %>
  <%= f.text_area :content %>
  <button class="btn">Submit</button>
<% end %>
<div id="msgs">
</div>

messages_controller.rb¶ ↑

Create a function named websocket in your controller to handle the request

class MessagesController < ApplicationController
  def websocket(params, socket)
    message = Message.create(params[:message])
    socket.broadcast(message, :create_message)
  end
end

javascript¶ ↑

Bind the event you triggered in the controller

Socketable.dispatcher().bind('create_message', function(data) {
  $('#msgs').append($('<div></div>').html(data.content));
});