Skip to content

Instantly share code, notes, and snippets.

@afomi

afomi/ember.js.md

Last active Aug 29, 2015
Embed
What would you like to do?
Ember.js

Basics

A request comes in. A URL comes in. And the request is handled by router.js.coffee and a /routes/*_route.js.coffee file.

Assumptions

  • The name of my example Ember App is App.
  • I'm using coffee-script, and I'm assuming it gets compiled to javascript.

Router

/app/router.js.coffee

App.Router.map ->
  @resource "jurisdictions", ->
    @route 'new'
  @resource "jurisdiction", path: '/jurisdictions/:id', ->
    @route 'edit'
    

A Route

You'll have one Route for every URL you have for your site. /, /about, /signup, /login, /widget, /widget/:id.

/app/routes/agencies_route.js.coffee

App.AgenciesRoute = Ember.Route.extend
  model: ->
    @store.find('agency')

App.AgenciesNewRoute = Ember.Route.extend
  # setupController: ->
    # @store.createRecord('agency',
    #   name: "Default Name"
    # )
  renderTemplate: ->
    @render into: "application"

Controller.js.coffee

Properties

Model.js.coffee

DS.attr("string")

View.js.coffee

UI Behaviors

Template.hbs

HTML + Handlebars

Components

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