Skip to content

Instantly share code, notes, and snippets.

@phillbaker
Last active December 27, 2015 02:29
Show Gist options
  • Save phillbaker/7252790 to your computer and use it in GitHub Desktop.
Save phillbaker/7252790 to your computer and use it in GitHub Desktop.
Rails + Backbone setup
mkdir -p app/assets/javascripts/backbone/lib/ \
app/assets/javascripts/backbone/models/ \
app/assets/javascripts/backbone/routers/ \
app/assets/javascripts/backbone/templates/ \
app/assets/javascripts/backbone/views/
touch app/assets/javascripts/backbone/lib/.keep \
app/assets/javascripts/backbone/models/.keep \
app/assets/javascripts/backbone/routers/.keep \
app/assets/javascripts/backbone/templates/.keep \
app/assets/javascripts/backbone/views/.keep
mkdir -p vendor/assets/javascripts
curl http://backbonejs.org/backbone.js > vendor/assets/javascripts/backbone.js
curl http://underscorejs.org/underscore.js > vendor/assets/javascripts/underscore.js
touch app/assets/javascripts/backbone/[app_name].coffee
...
//= require underscore
//= require backbone
//= require backbone/[app_name]
...
#= require_self
#= require_tree ./lib
#= require_tree ./models
#= require_tree ./routers
#= require_tree ./templates
#= require_tree ./views
window.[app_name] =
Lib: {}
Models: {}
Collections: {}
Routers: {}
Views: {}
class [app_name].Models.[model] extends Backbone.Model
defaults: {}
class [app_name].Collections.[model] extends Backbone.Collection
model: [app_name].Models.[model]
url: '/path/to/model/json/api'
class [app_name].Routers.[router] extends Backbone.Router
initialize: (options) ->
routes:
"/path": "function"
class [app_name].Views.[view] extends Backbone.View
template: JST["template"]
events: {}
# "click .destroy" : "destroy"
initialize: (options) ->
@options ||= options
render: ->
@phillbaker
Copy link
Author

/cc @ddgromit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment