SlideShare a Scribd company logo
By: Ashan Fernando
   Introduction
   Technology Stack
   Project Structure
   High Level Architecture
   Frontend Architecture MVC
       View

       Collection

       Model

       Routes

   Backend Architecture MVC overview
       View/ Controller/ Model/ Route
A single-page application (SPA), also known
 as single-page interface (SPI), is a web
 application or web site that fits on a single
 web page with the goal of providing a more
 fluid user experience akin to a desktop
 application.

 ~ wikipedia
Ruby on Rails                           Java Script
   (Backend)                              (Frontend)
Jammit or Rails 3.1 + Asset           Backbone
Pipeline
                                      Backbone Relational
• Asset Packaging for Rails

RABL                                  Underscore
• (Ruby API Builder Language)         JQuery
DEVICE
                                      JQueryUI
• Authentication solution for Rails
                                      Modernizr
* Database
• MySQL                               Uniform
app/
        controllers/
          books_controller.rb
        models/
          book.rb
        views/
          books/
            index.rabl
          frontend/
            books/
              book.jst
        routes/
            routes.rb
       public/
         javascripts/
           application.js
           routes/
             booksAppRouter.js
           models/
             book.js
             library.js
           views/
             bookView.js​​

      Apart from this, the Database configuration/ Asset configurations are stored
       separately in respective folders
Ruby on Rails Platform
                                                                    Front End
                                                                    Web App
        Rails MVC
   RESTful Services & Content                                      Backbone MVC

                                                                    Collections
                                Routes         HTTP/JSON Request

       Controller                                                    Model
                                                                                  R
                                   HTTP/JSON Response                             o
                                                                                  u
                                                                                  t
                 Model                                                            e
                                   MySQL DB                          View         s

         View
var bookView = Backbone.View.extend({
        template: “books / book.jst",
        // reference to JST template
        events: {
           "click .icon": "open"
        },
        initialize() {
           this.render();
        },
        render: function() {
          var book = this.model.toJSON();
             $(this.el).html(this.JST({
                book: book
             }));
        },
        open: function() { // book open logic goes here
    }
   });
   When using this technology stack, the view content (HTML) are stored in JST
    files.
   At runtime JST files are converted into JavaScript functions (Underscore
    Template functions) using the Asset Pipeline (Jammit).

   Book.jst
       <h1><%= book.title %></h1>
        <div><%= book.content %></div>
        <div><%= book.footer %></div>

   Book JST after conversion to JavaScript
       var JST.book = function(book) {
           var out = "<h1>" + book.title + "</h1>";
           out += "<div>" + book.content + "</div>";
           out += "<div>" + book.footer + "</div>";
        }​
   Backbone collection is bind to a rest service
    using its url attribute

   var books = Backbone.Collection.extend({
       model: Book,
       url: '/books.json'
    });
   var book = Backbone.Model.extend({
    });
   A plug-in called backbone relational also can be used to add
    several models in relationship with eachother.
   var library = Backbone.RelationalModel.extend({
       relations: [{
         type: Backbone.HasMany,
         key: 'books',
         relatedModel: 'Book',
         reverseRelation: {
            key: 'storedAt',
            type: Backbone.HasOne
         }}]
    });
   Routes maps the request to the respective controller (request
    URL/operation mapping to controller)

   Controllers fetch a instance of a model and render the particular model
    using the respective view

   The instance of the model queried in the controller is readily available for
    the view and it renders the content using the respective model instance
    data. (HTML or JSON based on view template)

   Model reflects the instance of a database table in language structure

   All the assets (JavaScript/ Images/ CSS & etc.) are stored in Asset.yml and
    added to the respective resources using the asset pipeline (Jammit)

More Related Content

PPTX
Ruby on Rails + AngularJS + Twitter Bootstrap
PDF
Using Angular with Rails
PDF
RoR 101: Session 2
PDF
Rails 2.3 and Rack - NHRuby Feb 2009
PDF
Rails::Engine
PPTX
Building a dashboard using AngularJS
PPT
jQuery and AJAX with Rails
PDF
Introduction to AngularJS For WordPress Developers
Ruby on Rails + AngularJS + Twitter Bootstrap
Using Angular with Rails
RoR 101: Session 2
Rails 2.3 and Rack - NHRuby Feb 2009
Rails::Engine
Building a dashboard using AngularJS
jQuery and AJAX with Rails
Introduction to AngularJS For WordPress Developers

What's hot (20)

PDF
Active Admin
PDF
AngularJS with Slim PHP Micro Framework
PDF
jQuery and Rails: Best Friends Forever
PDF
SproutCore and the Future of Web Apps
PDF
Introduction à Ruby
PPTX
Intro to Rails Give Camp Atlanta
PPT
jQuery Intro
PDF
PLAT-8 Spring Web Scripts and Spring Surf
PPTX
Building rich Single Page Applications (SPAs) for desktop, mobile, and tablet...
PPTX
Catalog display
PPTX
The Chaos Tools Suite
PDF
Ember,js: Hipster Hamster Framework
PDF
Ch. 9 jsp standard tag library
DOCX
multiple views and routing
PPTX
Dash of ajax
KEY
Leveraging the Chaos tool suite for module development
PDF
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
PDF
Ch. 8 script free pages
ODP
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
PDF
AngularJS Best Practices
Active Admin
AngularJS with Slim PHP Micro Framework
jQuery and Rails: Best Friends Forever
SproutCore and the Future of Web Apps
Introduction à Ruby
Intro to Rails Give Camp Atlanta
jQuery Intro
PLAT-8 Spring Web Scripts and Spring Surf
Building rich Single Page Applications (SPAs) for desktop, mobile, and tablet...
Catalog display
The Chaos Tools Suite
Ember,js: Hipster Hamster Framework
Ch. 9 jsp standard tag library
multiple views and routing
Dash of ajax
Leveraging the Chaos tool suite for module development
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Ch. 8 script free pages
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
AngularJS Best Practices
Ad

Similar to SPA using Rails & Backbone (20)

ODP
iPhone Web Development and Ruby On Rails
PPTX
Single Page Applications on JavaScript and ASP.NET MVC4
PPTX
Getting into ember.js
PDF
Ruby on rails RAD
PPT
Ruby On Rails Siddhesh
PPT
MVC
KEY
Javascript Frameworks for Well Architected, Immersive Web Apps
PDF
Client Side MVC with Backbone and Rails
PPT
A Semantic Wiki Based Light-Weight Web Application Model
PDF
Content-Driven Web Applications with Magnolia CMS and Ruby on Rails
PDF
Spring mvc 2.0
PPT
Jasig Rubyon Rails
PDF
Spring MVC introduction HVA
PPTX
BackboneJS + ReactJS
PPT
Rails
 
PPT
Introduction to the Servlet / JSP course
PPSX
Introduction to backbone_js
PPTX
Writing HTML5 Web Apps using Backbone.js and GAE
PDF
quickguide-einnovator-7-spring-mvc
PPT
Ruby On Rails Tutorial
iPhone Web Development and Ruby On Rails
Single Page Applications on JavaScript and ASP.NET MVC4
Getting into ember.js
Ruby on rails RAD
Ruby On Rails Siddhesh
MVC
Javascript Frameworks for Well Architected, Immersive Web Apps
Client Side MVC with Backbone and Rails
A Semantic Wiki Based Light-Weight Web Application Model
Content-Driven Web Applications with Magnolia CMS and Ruby on Rails
Spring mvc 2.0
Jasig Rubyon Rails
Spring MVC introduction HVA
BackboneJS + ReactJS
Rails
 
Introduction to the Servlet / JSP course
Introduction to backbone_js
Writing HTML5 Web Apps using Backbone.js and GAE
quickguide-einnovator-7-spring-mvc
Ruby On Rails Tutorial
Ad

Recently uploaded (20)

PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Modernizing your data center with Dell and AMD
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPT
Teaching material agriculture food technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Cloud computing and distributed systems.
PDF
Advanced IT Governance
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Network Security Unit 5.pdf for BCA BBA.
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The AUB Centre for AI in Media Proposal.docx
Modernizing your data center with Dell and AMD
Unlocking AI with Model Context Protocol (MCP)
Understanding_Digital_Forensics_Presentation.pptx
Teaching material agriculture food technology
20250228 LYD VKU AI Blended-Learning.pptx
Cloud computing and distributed systems.
Advanced IT Governance

SPA using Rails & Backbone

  • 2. Introduction  Technology Stack  Project Structure  High Level Architecture  Frontend Architecture MVC  View  Collection  Model  Routes  Backend Architecture MVC overview  View/ Controller/ Model/ Route
  • 3. A single-page application (SPA), also known as single-page interface (SPI), is a web application or web site that fits on a single web page with the goal of providing a more fluid user experience akin to a desktop application. ~ wikipedia
  • 4. Ruby on Rails Java Script (Backend) (Frontend) Jammit or Rails 3.1 + Asset Backbone Pipeline Backbone Relational • Asset Packaging for Rails RABL Underscore • (Ruby API Builder Language) JQuery DEVICE JQueryUI • Authentication solution for Rails Modernizr * Database • MySQL Uniform
  • 5. app/ controllers/ books_controller.rb models/ book.rb views/ books/ index.rabl frontend/ books/ book.jst routes/ routes.rb public/ javascripts/ application.js routes/ booksAppRouter.js models/ book.js library.js views/ bookView.js​​  Apart from this, the Database configuration/ Asset configurations are stored separately in respective folders
  • 6. Ruby on Rails Platform Front End Web App Rails MVC RESTful Services & Content Backbone MVC Collections Routes HTTP/JSON Request Controller Model R HTTP/JSON Response o u t Model e MySQL DB View s View
  • 7. var bookView = Backbone.View.extend({ template: “books / book.jst", // reference to JST template events: { "click .icon": "open" }, initialize() { this.render(); }, render: function() { var book = this.model.toJSON(); $(this.el).html(this.JST({ book: book })); }, open: function() { // book open logic goes here } });
  • 8. When using this technology stack, the view content (HTML) are stored in JST files.  At runtime JST files are converted into JavaScript functions (Underscore Template functions) using the Asset Pipeline (Jammit).  Book.jst  <h1><%= book.title %></h1> <div><%= book.content %></div> <div><%= book.footer %></div>  Book JST after conversion to JavaScript  var JST.book = function(book) { var out = "<h1>" + book.title + "</h1>"; out += "<div>" + book.content + "</div>"; out += "<div>" + book.footer + "</div>"; }​
  • 9. Backbone collection is bind to a rest service using its url attribute  var books = Backbone.Collection.extend({ model: Book, url: '/books.json' });
  • 10. var book = Backbone.Model.extend({ });  A plug-in called backbone relational also can be used to add several models in relationship with eachother.  var library = Backbone.RelationalModel.extend({ relations: [{ type: Backbone.HasMany, key: 'books', relatedModel: 'Book', reverseRelation: { key: 'storedAt', type: Backbone.HasOne }}] });
  • 11. Routes maps the request to the respective controller (request URL/operation mapping to controller)  Controllers fetch a instance of a model and render the particular model using the respective view  The instance of the model queried in the controller is readily available for the view and it renders the content using the respective model instance data. (HTML or JSON based on view template)  Model reflects the instance of a database table in language structure  All the assets (JavaScript/ Images/ CSS & etc.) are stored in Asset.yml and added to the respective resources using the asset pipeline (Jammit)

Editor's Notes

  • #4: A single-page application (SPA), also known as single-page interface (SPI), is a web application or web site that fits on a single web page with the goal of providing a more fluid user experience akin to a desktop application.The way traditional web applications work causes disruption in the user experience and workflow.SPAs address these issues by requiring no page reload by the browser during an application session. All user interaction and changes of the application state are handled in the context of a single Web document.