Skip to content

Instantly share code, notes, and snippets.

@rubiety
Created May 14, 2011 06:36
Show Gist options
  • Save rubiety/971993 to your computer and use it in GitHub Desktop.
Save rubiety/971993 to your computer and use it in GitHub Desktop.
Jazzity Rails + Backbone.js + Coffeescript Example
class Scale < ActiveRecord::Base
include KeyContext
has_many :tones, :class_name => 'ScaleTone', :extend => ToneSequence, :dependent => :destroy
delegate :notes, :to => :tones
end
class ScalesController < ApplicationController
respond_to :html, :json
def index
@scales = Scale.active
respond_with @scales
end
def show
@scale = Scale.find(params[:id])
respond_with @scale
end
end
Jazzity.Scale = Backbone.Model.extend url: -> "/scales/" + this.id
major = new Jazzity.Scale id: "major"
major.fetch # HTTP GET /scales/major.json
# major.attributes =>
# {
# name: "The Major Scale",
# notes: ["C", "D", "E", "F", "G", "A", "B"],
# symmetric: false
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment