quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

Building an Ember app with RailsAPI

Building an Ember app with RailsAPI - Part 1

  1. Generated a new app using rails-api
  2. Set up the javascript and stylesheet assets
  3. Wrote a very simple JSON API for returning all users

Building an Ember app with RailsAPI - Part 2

assets追加のところで

$ git add .
fatal: CRLF would be replaced by LF in vendor/assets/javascripts/jquery.js.

出た。追加したファイルを開いて保存して、エディタの改行変換を通したらOKだった。

Emberのセットアップ

$ mkdir -p app/assets/javascripts/{controllers,models,views,templates}

Serializer - this will instruct Rails to turn our ActiveRecord object into a JSON object properly normalized for Ember

class UserSerializer < ActiveModel::Serializer
  attributes :id, :first_name, :last_name, :quote
end

application_controller

class ApplicationController < ActionController::API
end

custom FormatTest class in config/routes.rb

map certain routes to JSON requests and certain routes to HTML requesets.

handlebars_assets, Ember.TEMPLATES, config/initializers/handlebars_assets.rb

{{outlet}} = yield

History API

App.Router.reopen
  location: 'history'
  rootURL: '/'

/ -> index -> App.IndexController -> render index template

Controller

window.App = Ember.Application.create()
App.ApplicationController = Ember.Controller.extend

App.IndexRoute = Ember.Route.extend in routes.coffee
setupController - automatically called on each visit to the route this.controllerFor

App.Store = DS.Store.extend
App.User = DS.Model.extend(

App.User.find() makes a remote call, fetches the collection, and instantizes the models

途中でチュートリアル通りいかなくなったら、やはり間違えていた

ここまで

一番の課題は、問題が起きたとき(typo, syntax error)あまり情報が得られないこと
画面は部分的にただ真っ白になるだけ