Backbone code in a Rails 4 application

When using Backbone in a Rails app, you’ll have two kinds of Backbone-related assets: classes and templates


Rails 4 introduced the asset pipeline, which uses the Sprockets library for p reprocessing and packaging assets. To take advantage of the built-in asset pipeline, organize your Backbone templates and classes in paths available to it: classes go in app/assets/javascripts/, and templates go alongside, in app/assets/templates/:

app/
   assets/
      javascripts/
         collections/
                  todos.js
         models/
                  todo.js
         routers/
                  todos_router.js
         views/
                  todos/
                  todos_index.js
         templates/
                  todos/
                  index.jst.ejs
                  show.jst.ejs

Its Basically the Structure of Using Backbone in Rails Application, its totally similar Like Rails Application structure, Just the difference is, Here we are working in Javascripts Directory, and Using MVC, structure

Note: In Backbone, MVC means, Models, Views and Collections not Controller.

Also We use another fields like, Routers and templates. Templates works as a View in backbone, and these templates and routers and other javascripts call in javascripts, You can view it at example app/app/assets/javascripts/application.js.

//= require jquery
//= require jquery_ujs
//= require jquery-ui-1.8.18.custom.min
//
//= require underscore
//= require json2
//= require backbone
//= require backbone-support
//
//= require backbone-forms.js
//= require jquery-ui-editors.js
//= require uploader.js
//
//= require example_app
//
//= require_tree ./models
//= require_tree ./collections
//= require_tree ./views
//= require_tree ./routers
//= require_tree ../templates
//= require_tree


Comments