SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Downloaden Sie, um offline zu lesen
Ember.js for Rails
Developers
Tech Talk - Feb. 21, 2014
Aaron Ortbals
What we’ll be doing
•

Building a Github Stat Tracker in Ember

•

Work alone or in pairs

•

Discuss various aspects of using Ember,
Javascript, and their associated ecosystems along
the way
You’ll Need
•

Homebrew

•

Git

!

brew install git!
•

!

Ruby
brew install rbenv ruby-build!
rbenv install 2.0.0-p353 # at least 1.9.3!
rbenv rehash!
gem update --system!
gem install bundler rails!

•

NPM, bower

!

brew install node!
npm install -g bower!
•

Clone the repo

!

git clone https://github.com/aortbals/ember-github-example!
bundle install
Build Tools
•

A build system:
•
•

prepares them for deployment

•

•

compiles your assets

serves them in development

Caring about tooling is important
Comparing Toolsets
•

ember-rails (what we are using)!
•

•

ember-app-kit!
•

•

rake, sprockets, internal REST API, rubygems

JS, grunt, npm, bower, ES6 modules

ember-appkit-rails!
•

ember app kit conventions, sprockets, rubygems
Future Build Tools
•

Broccoli is a build system meant to alleviate many
of the issues with grunt (and others)

•

Goal of building in < 200ms

•

O(1) build time as the app gets bigger

•

Ember will likely standardize on this in the core
library

•

Easy transition from Ember App Kit
What's in the repo
•

I've built a basic Rails 4 API that we can use to
consume Github

•

Turbolinks is removed

•

Provides a REST API, rake, build system
(sprockets), little else

•

Gives us more time to focus on Ember
What’s in the repo
•

SCSS
•

Bourbon: SCSS mixins

•

Bourbon Neat: semantic grid

•

Bitters: predefined typography, lists, etc

•

A basic layout

•

We will be building some components on top of the
basic layout
v0.1

How we’ll work
•

Checkout a tag and make a practice branch
!
git checkout v0.1!
git checkout -b practice!

•

Follow along, look for a

when we hit a new tag

•

We can go back to master and jump to a different step.
Stash your changes, commit them, or throw them away
!
git reset HEAD --hard!
# or `git stash save "my progress"`!
# or `git commit`!
git checkout master!
git checkout v0.2

Tip: List tags!

!

git tag -n!

!

v0.1
v0.2

Getting started!
Step 2
Ember Rails, Releases
•

Gemfile	

!
...	
gem 'ember-rails'	
gem 'ember-source', '~> 1.4.0'	
gem 'ember-data-source', '~> 1.0.0.beta.6’	
...	

!
•

Check http://emberjs.com/builds for the latest releases

•

Ember has been very stable since 1.0; no breaking changes

•

Adopted Chrome-style release cycle with semantic versioning
v0.1

Generating Ember
Scaffolding
•

Let's start by using ember-rails to generate our
directory structure
!
rails generate ember:bootstrap!

•

Ember App Kit (and EAK-rails) promote JS to the
top level - no more nested app/assets/
javascripts/
v0.2

Namespaced API
•

Let's setup our Rails API and configure Ember

!
EmberGithubExample::Application.routes.draw do!
get 'app/index'!
root to: 'app#index'!
!
namespace :api do!
# resources :users!
# ...!
end!
!
# Match all remaining paths and direct to Ember!
get '*path' => 'app#index'!
...
One view, one controller
•

app/controllers/app_controller.rb	

!
class AppController < ApplicationController!
def index!
end!
end!
•

touch app/views/app/index.html
v0.2

Setup our rails application
template
•

Bundle all templates together thanks to Sprockets

•

views/layouts/application.html.erb	

!

<!DOCTYPE html>!
<html>!
<head>!
<title>EmberGithubExample</title>!
<%= stylesheet_link_tag
"application", media: "all" %>!
<%= javascript_include_tag "application" %>!
<%= javascript_include_tag "templates/all" %>!
<%= csrf_meta_tags %>!
</head>!
<body>!

!

<%= yield %>!

!

</body>!
</html>!
•

!

app/assets/javascripts/template/all.js
//= require_tree .
v0.2

Configure Ember's
namespace
•

store.js	
!
EmberGithubExample.ApplicationAdapter =
DS.ActiveModelAdapter.extend!
namespace: 'api'!
!
EmberGithubExample.Store = DS.Store.extend!
# Our custom adapter extends `DS.ActiveModelAdapter`!
# with a namespace for our API!
adapter: 'EmberGithubExample.ApplicationAdapter'
v0.2

Setup the Ember app
•

application.js.coffee

- better logging in dev

!
window.EmberGithubExample = Ember.Application.create({!
LOG_TRANSITIONS: true,!
LOG_ACTIVE_GENERATION: true,!
LOG_VIEW_LOOKUPS: true!
})!

•

Sprockets and Rails take care of compiling your
app - makes it very easy to get started
v0.2

Let's hello world!
•

Ember will render the default application.hbs

!
<header>Welcome to the Github Stat Tracker!</header>!
<section class="app">!
</section>!
<footer></footer>
v0.2

Using Bower with Rails
•

Bower is a client-side package manager

•

Don't vendor stuff. Just don't.

•

.bowerrc	

!

{!
"directory": "vendor/assets/components"!
}!
•

bower.json	

!

{!
"name": "ember-github-example",!
"dependencies": {!
"ember-data-extensions": "~1.0.0-beta.7"!
}!
}!

*I blogged about this
v0.2

Ember Data
•

Makes it easy to retrieve records from the server

•

Abstracts away the request/response cycle with a
robust data model

•

Provides an ORM-like experience

•

Works well with Rails

•

Ember Data is a stable beta
v0.2

Talking with Github
•

We have a basic REST API to query events for an
organization
!
localhost:3000/api/events?org=chaione!

•

See https://developer.github.com/v3/activity/events/
v0.2

Models
•

A model looks like this:

!

App.User = DS.Model.extend!
  firstName:  DS.attr('string')!
  lastName:   DS.attr('string')!
  email:      DS.attr('string')!
  username:   DS.attr('string')!
company:   DS.belongsTo('company')!
createdAt: DS.attr('date')!
•

Find a user:
!
user = App.User.find({ name: "Aaron" })!

•

belongsTo == hasOne
v0.2

Building some models
[	
{	

•

Repo

•

Actor

•

Org

•

"type": "Event",	
"public": true,	
"payload": {	
},	
"repo": {	
"id": 3,	
"name": "octocat/Hello-World",	
},	
"actor": {	
"login": "octocat",	
"gravatar_id": "somehexcode",	
},	
"org": {	
"id": 1,	
"login": "github",	
},	
"created_at": "2011-09-06T17:26:27Z",	
"id": "12345"	

Event - Go!

}	
]
v0.3

Event
EmberGithubExample.Event = DS.Model.extend!
type:
DS.attr('string')!
public:
DS.attr('string')!
createdAt: DS.attr('date')!
actor:
DS.belongsTo('actor')!
repo:
DS.belongsTo('repo')!
org:
DS.belongsTo('org')!

•

Models can have relationships

•

hasMany is supported
v0.3

The Adapter
•

Ember has what is called 'the adapter'

•

The adapter is responsible for translating data from
a REST API to models

•

Important to understand when a REST API does not
adhere to expected conventions or is not consistent

•

Ember Rails sets our adapter to
DS.ActiveModelAdapter which works out of the box
with Rails + ActiveModelSerializers
v0.3

Polymorphic Associations!
App.Like = DS.Model.extend!
user:
DS.belongsTo('user')!
likeable:
DS.belongsTo('likeable', {polymorphic: true})!
!
!
App.Likeable = DS.Model.extend!
likes: DS.hasMany('like')!
!
!
App.Album = App.Likeable.extend!
likes: DS.hasMany('like')!
!
!
App.User = DS.Model.extend!
likes: DS.hasMany('like')
v0.4

Router
•

Ember represents each of the possible states in your
application as a URL
!

interacts

event

!
•

The user can use the back button

•

Avoids losing state

•

If you hit refresh and the state changes, then 😂
v0.4

Router Example
!
•

Static routes
!

•

Resource routes

•

Nested resources

App.Router.map (match) ->!
  @route 'app', { path: '/'}!
  @route 'login'!
  @route 'signup'!
 !
  @resource 'users', ->!
    @route 'new'!
    @resource 'user',!
      path: ':user_id'!
 !
  @resource 'albums', ->!
    @route 'new'!
  @resource 'album',!
    path: '/album/:album_id'!
v0.4

A route
•

Each route has a route handler

•

It finds the model, hands it to the controller, and
renders a template

!
App.UsersRoute = Ember.Route.extend	
  model: ->	
    App.User.find()	
 	
App.UsersNewRoute = Ember.Route.extend	
  model: ->	
    App.User.createRecord()	
 	
App.SignupRoute = App.UsersNewRoute
v0.4

Declare our route
•

https://api.github.com/orgs/chaione/events

!
EmberGithubExample.Router.map ()->!
@resource 'org', { path: '/orgs/:orgName' }, ->!
@resource 'events'!
!
!
# Use the browser history API!
EmberGithubExample.Router.reopen!
location: 'history'
v0.4

Event Route
•

A Route provides a model hook

!
EmberGithubExample.EventsRoute = Ember.Route.extend!
model: (params) ->!
orgName = @modelFor('org').orgName!
return [] unless orgName # No results!
!
@store.find('event', { org: orgName })

Route:
@resource 'org', { path: '/orgs/:orgName' }, ->!
@resource 'events'!
v0.4

Event Template
•

Ember uses Handlebars which wraps {{things}} in
curly braces

!
<div class="main">!
<div class="image"></div>!
<div class="text">!
<div class="title">{{type}} by {{actor.login}}</div>!
<div class="sub-title">!
<span class="point">{{createdAt}}</span>!
<span class="point">{{repo.name}}</span>!
</div>!
</div>!
</div>!
v0.4

Events Template
•

In the events template we loop over the route
model
!
<section class="results">!
{{#each model}}!
{{partial "event"}}!
{{/each}}!
</section>
v0.4

Controllers handle actions
•

Controllers handle actions on your current view
•

•

form submissions, clicks, etc

They can also decorate the model with computed
properties
v0.4

Events Controller
EmberGithubExample.ApplicationController =
Ember.Controller.extend!
queryField: null!
actions:!
search: ->!
if @get('queryField')!
@transitionTo('events', @get('queryField'))!
!
!
EmberGithubExample.EventsController =
EmberGithubExample.ApplicationController.extend({})!
v0.4

What do we have so far?
•

Models - represent our data from the server

•

Router - declared route for our URL

•

Route - hand the results data to our controller and
template

•

Events Template - loop over the results

•

Event Template - present the event data
v0.5

Computed Properties
App.Person = Ember.Object.extend!
firstName: null!
lastName: null!
!
fullName: (->!
"#{@get('firstName')} #{@get('lastName')}"!
).property('firstName', 'lastName')!
!
!
aaron = App.Person.create!
firstName: "Aaron"!
lastName: "Ortbals"!
!
aaron.get('fullName') # Aaron Ortbals
v0.5

Add the repo url
•

Add a computed property for the repo url

•

Modify the template to display the repo url

Go!
v0.5

Template Helpers
•

Build a helper when you want to present data in a
specific way

!
Ember.Handlebars.helper 'from-now', (date) ->!
return unless date!
moment(date).fromNow()!
!
!
<span>{{from-now createdAt}}</span>!
v0.5

Bower + Moment + Helper

•

Use moment to write a handlebars helper that
displays the relative time

Go!
v0.6

Demo

•

Let's take a look at what we have so far
v0.6

Add the gravatar image

•

Let's add it, shall we?
Components
•

Components combine:
!
!

View
(Events)

+

Controller
(Actions)

!

•

Use them to define reusable pieces of UI +
behavior in your application
x-spinner
<section class="center">!
{{x-spinner delay=300}}!
</section>!

!

App.XSpinnerComponent = Ember.Component.extend({!
lines
: 12, // The number of lines to draw!
...!

!
!
!

inserted: function() {!
this._showSpinner();!
}.on('didInsertElement'),!
teardown: function() {!
this.spinner.stop();!
}.on('willDestroyElement'),!

_showSpinner: function() {!
var target = this.get('element');!
this.spinner = new Spinner({ ... });!
this.spinner.spin(target);!
},!
});!

!

Ember.Handlebars.helper('x-spinner', App.XSpinnerComponent);
Diving Deeper
•

Complex actions

•

Components

•

Events

•

Animations

•

Real-time APIs

•

Authentication
What's Coming for Ember?
•

Ember Conf 2014

•

HTMLbars

•

Build tools and modules

•

Query params to hit release
Resources
•

emberjs.com/guides should be your first stop

•

Smashing Magazine: In-depth Into to Ember

•

Ember Community Twitter List

•

My Ember bookmarks
Thanks!

Weitere ähnliche Inhalte

Was ist angesagt?

Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Software, Inc.
 
Chef-Zero & Local Mode
Chef-Zero & Local ModeChef-Zero & Local Mode
Chef-Zero & Local ModeMichael Goetz
 
A Supermarket of Your Own: Running a Private Chef Supermarket
A Supermarket of Your Own: Running a Private Chef SupermarketA Supermarket of Your Own: Running a Private Chef Supermarket
A Supermarket of Your Own: Running a Private Chef SupermarketNell Shamrell-Harrington
 
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012Patrick McDonnell
 
Building a Private Supermarket for your Organization - ChefConf 2015
Building a Private Supermarket for your Organization - ChefConf 2015 Building a Private Supermarket for your Organization - ChefConf 2015
Building a Private Supermarket for your Organization - ChefConf 2015 Chef
 
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Software, Inc.
 
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksCIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksICF CIRCUIT
 
Introduction to Chef - Techsuperwomen Summit
Introduction to Chef - Techsuperwomen SummitIntroduction to Chef - Techsuperwomen Summit
Introduction to Chef - Techsuperwomen SummitJennifer Davis
 
Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015Jennifer Davis
 
Server Installation and Configuration with Chef
Server Installation and Configuration with ChefServer Installation and Configuration with Chef
Server Installation and Configuration with ChefRaimonds Simanovskis
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to ChefKnoldus Inc.
 
Chef ignited a DevOps revolution – BK Box
Chef ignited a DevOps revolution – BK BoxChef ignited a DevOps revolution – BK Box
Chef ignited a DevOps revolution – BK BoxChef Software, Inc.
 
Michelin Starred Cooking with Chef
Michelin Starred Cooking with ChefMichelin Starred Cooking with Chef
Michelin Starred Cooking with ChefJon Cowie
 
Chef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Software, Inc.
 
Chasing AMI - Building Amazon machine images with Puppet, Packer and Jenkins
Chasing AMI - Building Amazon machine images with Puppet, Packer and JenkinsChasing AMI - Building Amazon machine images with Puppet, Packer and Jenkins
Chasing AMI - Building Amazon machine images with Puppet, Packer and JenkinsTomas Doran
 
Introduction to Chef: Automate Your Infrastructure by Modeling It In Code
Introduction to Chef: Automate Your Infrastructure by Modeling It In CodeIntroduction to Chef: Automate Your Infrastructure by Modeling It In Code
Introduction to Chef: Automate Your Infrastructure by Modeling It In CodeJosh Padnick
 
Chef + AWS + CodeIgniter
Chef + AWS + CodeIgniterChef + AWS + CodeIgniter
Chef + AWS + CodeIgniterciconf
 

Was ist angesagt? (20)

Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
 
Chef-Zero & Local Mode
Chef-Zero & Local ModeChef-Zero & Local Mode
Chef-Zero & Local Mode
 
A Supermarket of Your Own: Running a Private Chef Supermarket
A Supermarket of Your Own: Running a Private Chef SupermarketA Supermarket of Your Own: Running a Private Chef Supermarket
A Supermarket of Your Own: Running a Private Chef Supermarket
 
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
 
Building a Private Supermarket for your Organization - ChefConf 2015
Building a Private Supermarket for your Organization - ChefConf 2015 Building a Private Supermarket for your Organization - ChefConf 2015
Building a Private Supermarket for your Organization - ChefConf 2015
 
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
 
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksCIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
 
Introduction to Chef - Techsuperwomen Summit
Introduction to Chef - Techsuperwomen SummitIntroduction to Chef - Techsuperwomen Summit
Introduction to Chef - Techsuperwomen Summit
 
Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015
 
SCALE 10x Build a Cloud Day
SCALE 10x Build a Cloud DaySCALE 10x Build a Cloud Day
SCALE 10x Build a Cloud Day
 
Server Installation and Configuration with Chef
Server Installation and Configuration with ChefServer Installation and Configuration with Chef
Server Installation and Configuration with Chef
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Chef ignited a DevOps revolution – BK Box
Chef ignited a DevOps revolution – BK BoxChef ignited a DevOps revolution – BK Box
Chef ignited a DevOps revolution – BK Box
 
Michelin Starred Cooking with Chef
Michelin Starred Cooking with ChefMichelin Starred Cooking with Chef
Michelin Starred Cooking with Chef
 
Chef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of Chef
 
Chasing AMI - Building Amazon machine images with Puppet, Packer and Jenkins
Chasing AMI - Building Amazon machine images with Puppet, Packer and JenkinsChasing AMI - Building Amazon machine images with Puppet, Packer and Jenkins
Chasing AMI - Building Amazon machine images with Puppet, Packer and Jenkins
 
Introduction to Chef: Automate Your Infrastructure by Modeling It In Code
Introduction to Chef: Automate Your Infrastructure by Modeling It In CodeIntroduction to Chef: Automate Your Infrastructure by Modeling It In Code
Introduction to Chef: Automate Your Infrastructure by Modeling It In Code
 
Chef + AWS + CodeIgniter
Chef + AWS + CodeIgniterChef + AWS + CodeIgniter
Chef + AWS + CodeIgniter
 
Understand Chef
Understand ChefUnderstand Chef
Understand Chef
 

Andere mochten auch

데이터읽어주는남자(4회) 최종
데이터읽어주는남자(4회) 최종데이터읽어주는남자(4회) 최종
데이터읽어주는남자(4회) 최종Hanyang University
 
Riding the Edge with Ember.js
Riding the Edge with Ember.jsRiding the Edge with Ember.js
Riding the Edge with Ember.jsaortbals
 
analyzing 3 contents pages of music magazines
analyzing 3 contents pages of music magazinesanalyzing 3 contents pages of music magazines
analyzing 3 contents pages of music magazinesLauren Ottley
 
데이터 시각화 그리고 과학
데이터 시각화 그리고 과학데이터 시각화 그리고 과학
데이터 시각화 그리고 과학Hanyang University
 
Design approach thinking & coding
Design approach thinking & codingDesign approach thinking & coding
Design approach thinking & codingHanyang University
 
데이터읽는남자 2
데이터읽는남자 2데이터읽는남자 2
데이터읽는남자 2Hanyang University
 
Alanine amino transferase_concentrations_are.17
Alanine amino transferase_concentrations_are.17Alanine amino transferase_concentrations_are.17
Alanine amino transferase_concentrations_are.17Giorgio Ibarra
 
Moocs analysis as open service innovation
Moocs analysis as open service innovationMoocs analysis as open service innovation
Moocs analysis as open service innovationHanyang University
 
비즈니스 에센셜 트렌드(최종)
비즈니스 에센셜 트렌드(최종)비즈니스 에센셜 트렌드(최종)
비즈니스 에센셜 트렌드(최종)Hanyang University
 
20160410 데이터 디자이너
20160410 데이터 디자이너20160410 데이터 디자이너
20160410 데이터 디자이너Hanyang University
 

Andere mochten auch (18)

Ibrahimitaniportfolio
IbrahimitaniportfolioIbrahimitaniportfolio
Ibrahimitaniportfolio
 
데이터읽어주는남자(4회) 최종
데이터읽어주는남자(4회) 최종데이터읽어주는남자(4회) 최종
데이터읽어주는남자(4회) 최종
 
Riding the Edge with Ember.js
Riding the Edge with Ember.jsRiding the Edge with Ember.js
Riding the Edge with Ember.js
 
Slow date project
Slow date projectSlow date project
Slow date project
 
analyzing 3 contents pages of music magazines
analyzing 3 contents pages of music magazinesanalyzing 3 contents pages of music magazines
analyzing 3 contents pages of music magazines
 
hyun-chul-roh/
hyun-chul-roh/hyun-chul-roh/
hyun-chul-roh/
 
데이터 시각화 그리고 과학
데이터 시각화 그리고 과학데이터 시각화 그리고 과학
데이터 시각화 그리고 과학
 
Design approach thinking & coding
Design approach thinking & codingDesign approach thinking & coding
Design approach thinking & coding
 
WWI in photos
WWI in photosWWI in photos
WWI in photos
 
Nom 030-ssa2-2009
Nom 030-ssa2-2009Nom 030-ssa2-2009
Nom 030-ssa2-2009
 
데이터읽는남자 2
데이터읽는남자 2데이터읽는남자 2
데이터읽는남자 2
 
Wintergirls
WintergirlsWintergirls
Wintergirls
 
Depression photos
Depression photosDepression photos
Depression photos
 
Wintergirls
WintergirlsWintergirls
Wintergirls
 
Alanine amino transferase_concentrations_are.17
Alanine amino transferase_concentrations_are.17Alanine amino transferase_concentrations_are.17
Alanine amino transferase_concentrations_are.17
 
Moocs analysis as open service innovation
Moocs analysis as open service innovationMoocs analysis as open service innovation
Moocs analysis as open service innovation
 
비즈니스 에센셜 트렌드(최종)
비즈니스 에센셜 트렌드(최종)비즈니스 에센셜 트렌드(최종)
비즈니스 에센셜 트렌드(최종)
 
20160410 데이터 디자이너
20160410 데이터 디자이너20160410 데이터 디자이너
20160410 데이터 디자이너
 

Ähnlich wie Chaione Ember.js Training

SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony AppsSymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony AppsPablo Godel
 
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony AppsSymfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony AppsPablo Godel
 
Using Nagios with Chef
Using Nagios with ChefUsing Nagios with Chef
Using Nagios with ChefBryan McLellan
 
Habitat Workshop at Velocity London 2017
Habitat Workshop at Velocity London 2017Habitat Workshop at Velocity London 2017
Habitat Workshop at Velocity London 2017Mandi Walls
 
Approaching APIs
Approaching APIsApproaching APIs
Approaching APIsRoss Singer
 
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Michael Lihs
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swaggerTony Tam
 
There and Back Again: How We Drank the Chef Kool-Aid, Sobered Up, and Learned...
There and Back Again: How We Drank the Chef Kool-Aid, Sobered Up, and Learned...There and Back Again: How We Drank the Chef Kool-Aid, Sobered Up, and Learned...
There and Back Again: How We Drank the Chef Kool-Aid, Sobered Up, and Learned...Chef
 
Angular2.0@Shanghai0319
Angular2.0@Shanghai0319Angular2.0@Shanghai0319
Angular2.0@Shanghai0319Bibby Chung
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with RailsAll Things Open
 
ITP Spacebrew Workshop - Spring 2014
ITP Spacebrew Workshop - Spring 2014ITP Spacebrew Workshop - Spring 2014
ITP Spacebrew Workshop - Spring 2014Brett Renfer
 
Continuous Automated Deployment with Apache ACE
Continuous Automated Deployment with Apache ACEContinuous Automated Deployment with Apache ACE
Continuous Automated Deployment with Apache ACEJan Willem Janssen
 
How to Contribute to Ansible
How to Contribute to AnsibleHow to Contribute to Ansible
How to Contribute to AnsibleCisco DevNet
 
Building a REST API Microservice for the DevNet API Scavenger Hunt
Building a REST API Microservice for the DevNet API Scavenger HuntBuilding a REST API Microservice for the DevNet API Scavenger Hunt
Building a REST API Microservice for the DevNet API Scavenger HuntAshley Roach
 
Tutorial 1: Your First Science App - Araport Developer Workshop
Tutorial 1: Your First Science App - Araport Developer WorkshopTutorial 1: Your First Science App - Araport Developer Workshop
Tutorial 1: Your First Science App - Araport Developer WorkshopVivek Krishnakumar
 
habitat at docker bud
habitat at docker budhabitat at docker bud
habitat at docker budMandi Walls
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer ToolboxPablo Godel
 

Ähnlich wie Chaione Ember.js Training (20)

SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony AppsSymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
 
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony AppsSymfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
 
Using Nagios with Chef
Using Nagios with ChefUsing Nagios with Chef
Using Nagios with Chef
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Habitat Workshop at Velocity London 2017
Habitat Workshop at Velocity London 2017Habitat Workshop at Velocity London 2017
Habitat Workshop at Velocity London 2017
 
Approaching APIs
Approaching APIsApproaching APIs
Approaching APIs
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swagger
 
There and Back Again: How We Drank the Chef Kool-Aid, Sobered Up, and Learned...
There and Back Again: How We Drank the Chef Kool-Aid, Sobered Up, and Learned...There and Back Again: How We Drank the Chef Kool-Aid, Sobered Up, and Learned...
There and Back Again: How We Drank the Chef Kool-Aid, Sobered Up, and Learned...
 
Angular2.0@Shanghai0319
Angular2.0@Shanghai0319Angular2.0@Shanghai0319
Angular2.0@Shanghai0319
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with Rails
 
ITP Spacebrew Workshop - Spring 2014
ITP Spacebrew Workshop - Spring 2014ITP Spacebrew Workshop - Spring 2014
ITP Spacebrew Workshop - Spring 2014
 
Continuous Automated Deployment with Apache ACE
Continuous Automated Deployment with Apache ACEContinuous Automated Deployment with Apache ACE
Continuous Automated Deployment with Apache ACE
 
How to Contribute to Ansible
How to Contribute to AnsibleHow to Contribute to Ansible
How to Contribute to Ansible
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
 
Building a REST API Microservice for the DevNet API Scavenger Hunt
Building a REST API Microservice for the DevNet API Scavenger HuntBuilding a REST API Microservice for the DevNet API Scavenger Hunt
Building a REST API Microservice for the DevNet API Scavenger Hunt
 
Tutorial 1: Your First Science App - Araport Developer Workshop
Tutorial 1: Your First Science App - Araport Developer WorkshopTutorial 1: Your First Science App - Araport Developer Workshop
Tutorial 1: Your First Science App - Araport Developer Workshop
 
habitat at docker bud
habitat at docker budhabitat at docker bud
habitat at docker bud
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
 

Kürzlich hochgeladen

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Kürzlich hochgeladen (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

Chaione Ember.js Training

  • 1. Ember.js for Rails Developers Tech Talk - Feb. 21, 2014 Aaron Ortbals
  • 2. What we’ll be doing • Building a Github Stat Tracker in Ember • Work alone or in pairs • Discuss various aspects of using Ember, Javascript, and their associated ecosystems along the way
  • 3. You’ll Need • Homebrew • Git ! brew install git! • ! Ruby brew install rbenv ruby-build! rbenv install 2.0.0-p353 # at least 1.9.3! rbenv rehash! gem update --system! gem install bundler rails! • NPM, bower ! brew install node! npm install -g bower! • Clone the repo ! git clone https://github.com/aortbals/ember-github-example! bundle install
  • 4. Build Tools • A build system: • • prepares them for deployment • • compiles your assets serves them in development Caring about tooling is important
  • 5. Comparing Toolsets • ember-rails (what we are using)! • • ember-app-kit! • • rake, sprockets, internal REST API, rubygems JS, grunt, npm, bower, ES6 modules ember-appkit-rails! • ember app kit conventions, sprockets, rubygems
  • 6. Future Build Tools • Broccoli is a build system meant to alleviate many of the issues with grunt (and others) • Goal of building in < 200ms • O(1) build time as the app gets bigger • Ember will likely standardize on this in the core library • Easy transition from Ember App Kit
  • 7. What's in the repo • I've built a basic Rails 4 API that we can use to consume Github • Turbolinks is removed • Provides a REST API, rake, build system (sprockets), little else • Gives us more time to focus on Ember
  • 8. What’s in the repo • SCSS • Bourbon: SCSS mixins • Bourbon Neat: semantic grid • Bitters: predefined typography, lists, etc • A basic layout • We will be building some components on top of the basic layout
  • 9. v0.1 How we’ll work • Checkout a tag and make a practice branch ! git checkout v0.1! git checkout -b practice! • Follow along, look for a when we hit a new tag • We can go back to master and jump to a different step. Stash your changes, commit them, or throw them away ! git reset HEAD --hard! # or `git stash save "my progress"`! # or `git commit`! git checkout master! git checkout v0.2 Tip: List tags! ! git tag -n! ! v0.1 v0.2 Getting started! Step 2
  • 10. Ember Rails, Releases • Gemfile ! ... gem 'ember-rails' gem 'ember-source', '~> 1.4.0' gem 'ember-data-source', '~> 1.0.0.beta.6’ ... ! • Check http://emberjs.com/builds for the latest releases • Ember has been very stable since 1.0; no breaking changes • Adopted Chrome-style release cycle with semantic versioning
  • 11. v0.1 Generating Ember Scaffolding • Let's start by using ember-rails to generate our directory structure ! rails generate ember:bootstrap! • Ember App Kit (and EAK-rails) promote JS to the top level - no more nested app/assets/ javascripts/
  • 12. v0.2 Namespaced API • Let's setup our Rails API and configure Ember ! EmberGithubExample::Application.routes.draw do! get 'app/index'! root to: 'app#index'! ! namespace :api do! # resources :users! # ...! end! ! # Match all remaining paths and direct to Ember! get '*path' => 'app#index'! ...
  • 13. One view, one controller • app/controllers/app_controller.rb ! class AppController < ApplicationController! def index! end! end! • touch app/views/app/index.html
  • 14. v0.2 Setup our rails application template • Bundle all templates together thanks to Sprockets • views/layouts/application.html.erb ! <!DOCTYPE html>! <html>! <head>! <title>EmberGithubExample</title>! <%= stylesheet_link_tag "application", media: "all" %>! <%= javascript_include_tag "application" %>! <%= javascript_include_tag "templates/all" %>! <%= csrf_meta_tags %>! </head>! <body>! ! <%= yield %>! ! </body>! </html>! • ! app/assets/javascripts/template/all.js //= require_tree .
  • 15. v0.2 Configure Ember's namespace • store.js ! EmberGithubExample.ApplicationAdapter = DS.ActiveModelAdapter.extend! namespace: 'api'! ! EmberGithubExample.Store = DS.Store.extend! # Our custom adapter extends `DS.ActiveModelAdapter`! # with a namespace for our API! adapter: 'EmberGithubExample.ApplicationAdapter'
  • 16. v0.2 Setup the Ember app • application.js.coffee - better logging in dev ! window.EmberGithubExample = Ember.Application.create({! LOG_TRANSITIONS: true,! LOG_ACTIVE_GENERATION: true,! LOG_VIEW_LOOKUPS: true! })! • Sprockets and Rails take care of compiling your app - makes it very easy to get started
  • 17. v0.2 Let's hello world! • Ember will render the default application.hbs ! <header>Welcome to the Github Stat Tracker!</header>! <section class="app">! </section>! <footer></footer>
  • 18. v0.2 Using Bower with Rails • Bower is a client-side package manager • Don't vendor stuff. Just don't. • .bowerrc ! {! "directory": "vendor/assets/components"! }! • bower.json ! {! "name": "ember-github-example",! "dependencies": {! "ember-data-extensions": "~1.0.0-beta.7"! }! }! *I blogged about this
  • 19. v0.2 Ember Data • Makes it easy to retrieve records from the server • Abstracts away the request/response cycle with a robust data model • Provides an ORM-like experience • Works well with Rails • Ember Data is a stable beta
  • 20. v0.2 Talking with Github • We have a basic REST API to query events for an organization ! localhost:3000/api/events?org=chaione! • See https://developer.github.com/v3/activity/events/
  • 21. v0.2 Models • A model looks like this: ! App.User = DS.Model.extend!   firstName:  DS.attr('string')!   lastName:   DS.attr('string')!   email:      DS.attr('string')!   username:   DS.attr('string')! company:   DS.belongsTo('company')! createdAt: DS.attr('date')! • Find a user: ! user = App.User.find({ name: "Aaron" })! • belongsTo == hasOne
  • 22. v0.2 Building some models [ { • Repo • Actor • Org • "type": "Event", "public": true, "payload": { }, "repo": { "id": 3, "name": "octocat/Hello-World", }, "actor": { "login": "octocat", "gravatar_id": "somehexcode", }, "org": { "id": 1, "login": "github", }, "created_at": "2011-09-06T17:26:27Z", "id": "12345" Event - Go! } ]
  • 23. v0.3 Event EmberGithubExample.Event = DS.Model.extend! type: DS.attr('string')! public: DS.attr('string')! createdAt: DS.attr('date')! actor: DS.belongsTo('actor')! repo: DS.belongsTo('repo')! org: DS.belongsTo('org')! • Models can have relationships • hasMany is supported
  • 24. v0.3 The Adapter • Ember has what is called 'the adapter' • The adapter is responsible for translating data from a REST API to models • Important to understand when a REST API does not adhere to expected conventions or is not consistent • Ember Rails sets our adapter to DS.ActiveModelAdapter which works out of the box with Rails + ActiveModelSerializers
  • 25. v0.3 Polymorphic Associations! App.Like = DS.Model.extend! user: DS.belongsTo('user')! likeable: DS.belongsTo('likeable', {polymorphic: true})! ! ! App.Likeable = DS.Model.extend! likes: DS.hasMany('like')! ! ! App.Album = App.Likeable.extend! likes: DS.hasMany('like')! ! ! App.User = DS.Model.extend! likes: DS.hasMany('like')
  • 26. v0.4 Router • Ember represents each of the possible states in your application as a URL ! interacts event ! • The user can use the back button • Avoids losing state • If you hit refresh and the state changes, then 😂
  • 27. v0.4 Router Example ! • Static routes ! • Resource routes • Nested resources App.Router.map (match) ->!   @route 'app', { path: '/'}!   @route 'login'!   @route 'signup'!  !   @resource 'users', ->!     @route 'new'!     @resource 'user',!       path: ':user_id'!  !   @resource 'albums', ->!     @route 'new'!   @resource 'album',!     path: '/album/:album_id'!
  • 28. v0.4 A route • Each route has a route handler • It finds the model, hands it to the controller, and renders a template ! App.UsersRoute = Ember.Route.extend   model: ->     App.User.find()   App.UsersNewRoute = Ember.Route.extend   model: ->     App.User.createRecord()   App.SignupRoute = App.UsersNewRoute
  • 29. v0.4 Declare our route • https://api.github.com/orgs/chaione/events ! EmberGithubExample.Router.map ()->! @resource 'org', { path: '/orgs/:orgName' }, ->! @resource 'events'! ! ! # Use the browser history API! EmberGithubExample.Router.reopen! location: 'history'
  • 30. v0.4 Event Route • A Route provides a model hook ! EmberGithubExample.EventsRoute = Ember.Route.extend! model: (params) ->! orgName = @modelFor('org').orgName! return [] unless orgName # No results! ! @store.find('event', { org: orgName }) Route: @resource 'org', { path: '/orgs/:orgName' }, ->! @resource 'events'!
  • 31. v0.4 Event Template • Ember uses Handlebars which wraps {{things}} in curly braces ! <div class="main">! <div class="image"></div>! <div class="text">! <div class="title">{{type}} by {{actor.login}}</div>! <div class="sub-title">! <span class="point">{{createdAt}}</span>! <span class="point">{{repo.name}}</span>! </div>! </div>! </div>!
  • 32. v0.4 Events Template • In the events template we loop over the route model ! <section class="results">! {{#each model}}! {{partial "event"}}! {{/each}}! </section>
  • 33. v0.4 Controllers handle actions • Controllers handle actions on your current view • • form submissions, clicks, etc They can also decorate the model with computed properties
  • 34. v0.4 Events Controller EmberGithubExample.ApplicationController = Ember.Controller.extend! queryField: null! actions:! search: ->! if @get('queryField')! @transitionTo('events', @get('queryField'))! ! ! EmberGithubExample.EventsController = EmberGithubExample.ApplicationController.extend({})!
  • 35. v0.4 What do we have so far? • Models - represent our data from the server • Router - declared route for our URL • Route - hand the results data to our controller and template • Events Template - loop over the results • Event Template - present the event data
  • 36. v0.5 Computed Properties App.Person = Ember.Object.extend! firstName: null! lastName: null! ! fullName: (->! "#{@get('firstName')} #{@get('lastName')}"! ).property('firstName', 'lastName')! ! ! aaron = App.Person.create! firstName: "Aaron"! lastName: "Ortbals"! ! aaron.get('fullName') # Aaron Ortbals
  • 37. v0.5 Add the repo url • Add a computed property for the repo url • Modify the template to display the repo url Go!
  • 38. v0.5 Template Helpers • Build a helper when you want to present data in a specific way ! Ember.Handlebars.helper 'from-now', (date) ->! return unless date! moment(date).fromNow()! ! ! <span>{{from-now createdAt}}</span>!
  • 39. v0.5 Bower + Moment + Helper • Use moment to write a handlebars helper that displays the relative time Go!
  • 40. v0.6 Demo • Let's take a look at what we have so far
  • 41. v0.6 Add the gravatar image • Let's add it, shall we?
  • 42. Components • Components combine: ! ! View (Events) + Controller (Actions) ! • Use them to define reusable pieces of UI + behavior in your application
  • 43. x-spinner <section class="center">! {{x-spinner delay=300}}! </section>! ! App.XSpinnerComponent = Ember.Component.extend({! lines : 12, // The number of lines to draw! ...! ! ! ! inserted: function() {! this._showSpinner();! }.on('didInsertElement'),! teardown: function() {! this.spinner.stop();! }.on('willDestroyElement'),! _showSpinner: function() {! var target = this.get('element');! this.spinner = new Spinner({ ... });! this.spinner.spin(target);! },! });! ! Ember.Handlebars.helper('x-spinner', App.XSpinnerComponent);
  • 45. What's Coming for Ember? • Ember Conf 2014 • HTMLbars • Build tools and modules • Query params to hit release
  • 46. Resources • emberjs.com/guides should be your first stop • Smashing Magazine: In-depth Into to Ember • Ember Community Twitter List • My Ember bookmarks