Created
March 7, 2014 06:15
-
-
Save bj-mcduck/9406222 to your computer and use it in GitHub Desktop.
Basic Ember Setup for Rails 4, Ember >1, Ember-Data 1Beta7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#= require ./store | |
#= require_tree ./models | |
#= require_tree ./controllers | |
#= require_tree ./views | |
#= require_tree ./helpers | |
#= require_tree ./components | |
#= require_tree ./templates | |
#= require_tree ./routes | |
#= require ./router | |
#= require_self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//app/assets/javascripts/application.js | |
//= require bootstrap | |
//= require handlebars | |
//= require ember | |
//= require ember-data | |
//= require_self | |
//= require app | |
// for more details see: http://emberjs.com/guides/application/ | |
App = Ember.Application.create({ | |
LOG_TRANSITIONS: true, | |
LOG_TRANSITIONS_INTERNAL: true, | |
LOG_VIEW_LOOKUPS: true | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# templates/application.js.hbs.hamlbars | |
%header | |
%nav.navbar.navbar-default.navbar-fixed-top | |
.container | |
.navbar-header | |
%btn.navbar-toggle{ data: { target: '.navbar-collapse', toggle: 'collapse' }, type: 'button' } | |
%span.sr-only Toggle Navigation | |
%span.icon-bar | |
%span.icon-bar | |
%span.icon-bar | |
= hb 'link-to "index" class="navbar-brand"' do | |
Mystics Managed | |
.collapse.navbar-collapse | |
%ul.nav.navbar-nav | |
%li | |
= hb 'link-to "dream_symbols"' do | |
Dream Symbols | |
%ul.nav.navbar-nav.navbar-right | |
%main | |
.container | |
= hb 'outlet' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#routes/application_route.js.coffee | |
App.ApplicationRoute = Ember.Route.extend | |
actions: | |
goToNewDreamSymbol: -> | |
@transitionTo 'dream_symbol.new' | |
goToDreamSymbol: (model)-> | |
@transitionTo 'dream_symbol', model | |
editSymbol: (model)-> | |
@transitionTo 'dream_symbol.edit', model.copy() | |
createSymbol: (model)-> | |
@storage.create model | |
@transitionTo 'dream_symbols' | |
updateSymbol: (model)-> | |
@storage.update model | |
@transitionTo 'dream_symbols' | |
removeSymbol: (model)-> | |
@storage.remove model | |
cancelSymbolUpdate: (model)-> | |
Ember.run model, "destroy" | |
@storage.refresh App.DreamSymbol | |
@transitionTo 'dream_symbols' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# attr = DS.attr | |
# models/dream_symbol.js.coffee | |
App.DreamSymbol = DS.Model.extend | |
# id: attr #'integer' | |
image: DS.attr 'string' | |
name: DS.attr 'string' | |
description: DS.attr 'string' | |
# interpretations: DS.hasMany 'interpretation' | |
serialize: -> | |
@getProperties [ 'guid', 'image', 'name', 'description' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# controllers/dream_symbols_controller.js.coffee | |
App.DreamSymbolsController = Ember.ArrayController.extend | |
sortProperties: ['title'] | |
sortAscending: false | |
actions: | |
newSymbol: -> | |
console.log "click" | |
createSymbol: -> | |
title = @get('title').trim | |
description = @get 'description' | |
if !title | |
return | |
symbol = @store.createRecord( | |
'dream_symbol' | |
title = title | |
description = description | |
isCompleted: false | |
) | |
symbol.save | |
@set 'title', '' | |
deleteSymbol: -> | |
symbol = @get 'destroyable' | |
symbol.invoke 'deleteRecord' | |
symbol.invoke 'save' | |
dreamSymbolsCount: (-> | |
@get 'model.length' | |
).property '@each' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# routes/dream_symbols_route.js.coffee | |
App.DreamSymbolsRoute = Ember.Route.extend() | |
model: -> | |
@store.findAll 'App.DreamSymbol' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For more information see: http://emberjs.com/guides/routing/ | |
App.Router.reopen | |
location: 'history' | |
App.Router.map -> | |
@resource 'dream_symbols', path: '/dream-symbols' | |
@resource 'dream_symbol', path: '/dream-symbols/:dream_symbol_id', -> | |
@route 'edit', path: 'edit' | |
@route 'destroy', path: 'destroy' | |
@resource 'dream_symbol.new', path: '/dream-symbols/new' | |
@route 'missing', path: '*:' | |
App.DreamSymbolsRoute = Ember.Route.extend | |
model: -> | |
@store.find 'dream_symbol' | |
App.DreamSymbolNewRoute = Ember.Route.extend | |
model: (params)-> | |
@store.find 'dream_symbol', params.dream_symbol_id | |
App.MissingRoute = Ember.Route.extend | |
redirect: -> | |
@transitionTo 'missing' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://emberjs.com/guides/models/using-the-store/ | |
# DS.RESTAdapter.reopen | |
# namespace: 'api/v1' | |
App.Store = DS.Store.extend( | |
adapter = DS.FixtureAdapter | |
) | |
App.ApplicationAdapter = DS.ActiveModelAdapter.extend() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment