Permalink
Browse files

Add installation instructions to README

  • Loading branch information...
1 parent 3f4b205 commit 1cb8cee5e7e9ad9afb60af8d735bb8f731b38af1 @jasonm jasonm committed Aug 28, 2011
Showing with 72 additions and 1 deletion.
  1. +72 −1 README.rdoc
View
@@ -1,3 +1,74 @@
= BackboneSyncRails
-This project rocks and uses MIT-LICENSE.
+Use this in a Rails 3.1 app. Right now the only supported pubsub messaging
+system is Faye http://faye.jcoglan.com/.
+
+== Installation
+
+This assumes you already have a Backbone.js + Rails app.
+
+1. Run a Faye server.
+2. Tell your app where the faye server is. This may differ per Rails.env.
+For now, let's say we add `config/initializers/backbone_sync_rails_faye.rb` with:
+
+```ruby
+BackboneSync::Rails::Faye.root_address = 'http://localhost:9292'
+```
+
+3. Pull in the javascripts:
+
+```javascript
+//= require extensions/backbone.collection.idempotent
+//= require backbone_sync-rails/rails_faye_subscriber
+
+```
+
+(Until I rewrite it, one of 'em uses coffeescript, so you'll need that.)
+
+4. Open a connection to Faye from your clients, somewhere on your page (in the layout?):
+
+```eruby
+<script type="text/javascript" src="<%= BackboneSync::Rails::Faye.root_address %>/faye.js"></script>
+```
+
+5. Observe model changes in Rails, and broadcast them. We provide the guts of
+an observer for you, so add a file like `app/models/user_observer.rb`:
+
+```ruby
+class UserObserver < ActiveRecord::Observer
+ include BackboneSync::Rails::Faye::Observer
+end
+```
+
+and enable it in `config/application.rb` like any good observer:
+
+```ruby
+module MyApp
+ class Application < Rails::Application
+ # snip...
+
+ # Activate observers that should always be running.
+ config.active_record.observers = :user_observer
+
+ # snip...
+ end
+end
+```
+
+6. Instantiate a new `BackboneSync.RailsFayeSynchronizer` for *each instance*
+of a Backbone collection you instantiate. You could do this in the
+collection's constructor, or do it by hand:
+
+Check it out! Open two browsers, do some stuff in one, and see your changes
+cascade to the other. It also assumes that your Backbone views will need to
+observe events on the collection like `change`, `add`, and `remove`.
+
+=== Installing on Rails < 3.1
+
+If you're on a version of Rails < 3.1, you'll probably have to copy some files
+into your app by hand, like the `vendor/assets` files. You'll probably have to
+require the `lib/backbone_sync-rails/faye.rb` file yourself, too.
+
+== Copyright
+
+Copyright (c) 2011 Jason Morrison. See MIT-LICENSE for details.

0 comments on commit 1cb8cee

Please sign in to comment.