Learn ralph small Learn

Backbone.js on Rails

Build snappier, more interactive apps with cleaner code and better tests in less time.

You build web apps, and you’ve seen the shift towards highly interactive, rich client-side web applications. Over the past years, we’ve seen the same things, and have built our apps, processes, and best practices around this. Learn the better way to build rich, interactive applications using Backbone.js and Rails.

More than just a book

In addition to the book (in HTML, PDF, EPUB, and Kindle formats), you also get a complete example application.

The book is written using Markdown and distributed via GitHub. When you purchase, we give you access directly to the repository, so you can use the GitHub comment and issue features to give us feedback about what we’ve written and what you’d like to see. Last but not least, also included is a complete sample Backbone.js and Rails application. What the book describes and explains, the example app demonstrates with real, working code. Fully up to date for Rails 3.2 and Backbone 1.0.

Table of Contents

  • Introduction

    • Why use Backbone.js
    • The Example Application
  • Getting up to speed

    • Backbone.js online resources
    • JavaScript online resources and books
  • Organization

    • Backbone.js and MVC
    • What Goes Where
    • Namespacing your application
    • Mixins
  • Rails Integration

    • Organizing your Backbone.js code in a Rails app
    • Rails 3.0 and prior
    • Rails 3.1 and above
    • An Overview of the Stack: Connecting Rails and Backbone.js
    • Customizing your Rails-generated JSON
    • Converting an existing page/view area to use Backbone.js
    • Automatically using the Rails authentication token
  • Routers, Views, and Templates

    • View explanation
    • Templating strategy
    • Choosing a strategy (stub)
    • Routers
    • Event binding
    • Cleaning Up: Unbinding
    • Swapping router
    • Composite views
    • Forms
    • Internationalization
  • Models and collections

    • Model associations
    • Filters and sorting
    • Validations
    • Model relationships
    • Duplicating business logic across the client and server
    • Synchronizing between clients
    • Uploading attachments
  • Testing

    • Full-stack integration testing
    • Isolated unit testing
    • Example: Test-driving a Task application
  • Security

    • XSS with JSON bootstrapping

The included example application illustrates a Rails 3.2 app with user authentication, nested model relationships, bootstrapped and lazily populated collections, and complete test coverage using Cucumber, RSpec, and Jasmine.