Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Backbone.js and Rails
Search
Matt Smith
March 28, 2013
Programming
69
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Backbone.js and Rails
A quick intro to using backbone.js with Ruby on Rails.
Matt Smith
March 28, 2013
Other Decks in Programming
See All in Programming
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
370
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
150
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
APNsからLive Activityを開始する話
yumnumm
0
170
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
220
[Dev Group Paris Octobre 26] Agentforce, SIforce, Claudeforce, Slackbot… on s'y retrouve ?
nabondance
0
110
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
1.6k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
Leo the Paperboy
mayatellez
10
2.4k
sira's awesome portfolio website redesign presentation
elsirapls
0
460
Practical Orchestrator
shlominoach
192
12k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Writing Fast Ruby
sferik
630
63k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
600
Six Lessons from altMBA
skipperchong
29
4.5k
Embracing the Ebb and Flow
colly
88
5.2k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
820
Transcript
Backbone.js & Rails A intro for Rails Developers Matt Smith
@symana matt@thinkific.com Wednesday, 27 March, 13
Agenda • What is Backbone.js? • Why backbone? • Integrating
with Rails Wednesday, 27 March, 13
What is Backbone.js? • Models & Collections to represent your
data • Views for declarative event handling & rendering • Templates (agnostic: eco, haml-js, ejs, etc.) • Connects to your RESTful JSON API Structure & Organization for JavaScript Wednesday, 27 March, 13
What it’s Not? • Not Opinionated == Flexible • Not
MVC Wednesday, 27 March, 13
Why Backbone? • Lightweight (10kb w/ Underscore.js) • Flexible •
Integrates with RESTful API • Test your Code • Mobile Friendly (mobile web or trigger.io/ phonegap) Wednesday, 27 March, 13
JavaScript & Rails Phase I Helpers (e.g. data- remote=true) Phase
II jQuery Spaghetti Phase III “PageObjects” & Tests Phase IV Frameworks (backbone) Source: Sarah Mei @ PivotalLabs Wednesday, 27 March, 13
What does it give you? • Model Mirroring (Models &
Collections) • Event Handling (Views) • Rendering (Templates) • History (Router) Wednesday, 27 March, 13
Integrating with Rails Wednesday, 27 March, 13
JavaScript Manifest // Backbone & Dependencies //= require jquery //=
require json2 //= require underscore //= require backbone // My Backbone Application Code //= require backbone/models //= require backbone/collections //= require backbone/views //= require backbone/routers //= require app //= require_tree ../templates Wednesday, 27 March, 13
class ProductsController < ApplicationController def index render :json => Product.all
end # Other RESTful actions... end Rails Controller Wednesday, 27 March, 13
Initialize App - javascript_tag $(function(){ app.initialize( = product.to_json ); });
Wednesday, 27 March, 13
app.js app = { models: {}, collections: {}, views: {},
initialize: function(productData){ app.product = new app.models.Product(productData); app.productView = new app.views.ProductView({ model: app.product }); } } Wednesday, 27 March, 13
models.js var app.models.Product = Backbone.Model.extend({ // Connects to Rails API
urlRoot: '/products', // Default properties defaults: { name: "My Default Name" }, // Constructor initialize: function() { }, // Called everytime set is called validate: function(attrs) { // Validate product attributes } }); Wednesday, 27 March, 13
var app.views.ProductView = Backbone.View.extend({ // Represents the actual DOM element
that corresponds to your View el: '#product', // Constructor initialize: function() { this.listenTo(this.model, 'change', this.render); this.render(); }, // Event Handlers events: { "click .add": "addToCart" }, render: function() { this.template = JST['products/index']; this.$el.html(this.template(model.toJson())); return this; }, addToCart: function() { // Add to the Cart this.model.addToCart(); } }); views.js Wednesday, 27 March, 13
index.ejs.jst <h1 class="name"> <%= name %> </h1> <p class="description"> <%=
description %> </p> <a class="add">Add to Cart</a> Wednesday, 27 March, 13
Thoughts • Backbone is probably best fit for transitioning to
add client-side interactivity to an existing rails app (e.g. Phase IV) Wednesday, 27 March, 13
Resources • PeepCode 3 Part Screencasts on Backbone • CodeSchool
Backbone • Backbone on Rails (Thoughtbot Book) • RailsCasts (very basic) • Backbone Docs & Annotated Source Code Wednesday, 27 March, 13
Thanks & Questions Wednesday, 27 March, 13