Ruby on Rails is awesome…why should you care about Backbone.js? Tim will give an overview of why Rails developers should care about Javascript MVC frameworks and how you can easily integrate one into a Rails application. He’ll also will explain the structure of a Backbone.js application and how the paradigm jives with its Rails counterparts. You should be able to walk away from this presentation and add Backbone.js to your resume.
Code here: https://github.com/timtyrrell/todo
12. Why Rails instead of Node.js or
Sinatra?
https://speakerdeck.com/u/brennandunn/p/rails-without-views
13. What is Backbone.js
Backbone.js gives structure to web applications
by providing:
● models with key-value binding and custom
events
● collections with a rich API of enumerable
functions
● views with declarative event handling
● connects it all to your existing API over a
RESTful JSON interface.
http://documentcloud.github.com/backbone/
15. Backbone.js Model
● Manages data for an application
● Not tied to markup, presentation, UI
● Validates itself
● Query methods (fetch, save)
16. Backbone.js Collection
● Manages an ordered set of models
● Fetches, add, removes models
● Gives you Underscore.js goodness
● Listens for model events
17. Backbone.js View
● Controller that responds to DOM events
● Displays data from a model w/template
● Reacts to model changes
● Reacts to DOM events
● Handle presentation logic for a part of the UI
18. Backbone.js Router
● Controller that responds to URL's
○ Hash Fragments (#page)
○ Standard URL's (/page)
● Generally sets up model w/ View
40. @collection.create
Started POST "/tasks" for 127.0.0.1 at 2012-05-20 17:16:17 -0500
Processing by TasksController#create as JSON
Parameters: {"name"=>"Walk the dog", "task"=>{"name"=>"Walk the dog"}}
(0.1ms) begin transaction
SQL (9.7ms) INSERT INTO "tasks" ("complete", "created_at", "name",
"updated_at") VALUES (?, ?, ?, ?) [["complete", nil], ["created_at", Sun, 20
May 2012 22:16:17 UTC +00:00], ["name", "Walk the dog"], ["updated_at", Sun,
20 May 2012 22:16:17 UTC +00:00]]
(1.8ms) commit transaction
Completed 201 Created in 19ms (Views: 2.7ms | ActiveRecord: 11.6ms)
44. @model.destroy()
Started DELETE "/tasks/5" for 127.0.0.1 at 2012-05-20 20:58:43 -0500
Processing by TasksController#destroy as JSON
Parameters: {"id"=>"5"}
Task Load (0.2ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = ?
LIMIT 1 [["id", "5"]]
(0.1ms) begin transaction
SQL (0.2ms) DELETE FROM "tasks" WHERE "tasks"."id" = ? [["id", 5]]
(2.9ms) commit transaction
Completed 204 No Content in 5ms (ActiveRecord: 3.3ms)
50. Other Libraries
● ModelBinder
○ HTML Binding
○ Recursive Binding
○ Calculated Fields
● Backbone-relational
○ one-to-one
○ one-to-many
○ many-to-one
● Backbone-validation
○ Validate model properties
○ Notify users of erros
51. Wrap Up
● A Javascript client-side MV* framework can
help you write better code.
○ It forces you separate the presentation logic away
from the business logic
○ It helps to make you javascript more testable
○ It allows for more responsive user experience
○ It is a tool that you will want to add to your toolbox
○ These same concepts apply to other JS frameworks
○ It is fun