Skip to content

Instantly share code, notes, and snippets.

@bj-mcduck
Created April 3, 2014 05:05
Show Gist options
  • Save bj-mcduck/9948549 to your computer and use it in GitHub Desktop.
Save bj-mcduck/9948549 to your computer and use it in GitHub Desktop.
Ember delete probs
# app/assets/javascripts/ember-app/controllers/dream_symbol_controllers.js.coffee
App.DreamSymbolsShowController = Ember.ArrayController.extend
dreamSymbolsCount: (->
@get 'model.length'
).property '@each'
App.DreamSymbolsEditController = Ember.ObjectController.extend
actions:
delete: ->
console.log 'deleted'
# Index Route
App.DreamSymbolsRoute = Ember.Route.extend
model: ->
@store.find 'dream_symbol'
actions:
new: ->
@transitionTo 'dream_symbols.new'
# Show Route
App.DreamSymbolsShowRoute = Ember.Route.extend
model: (params)->
@store.find 'dream_symbol', params.id
actions:
edit: ->
@transitionTo 'dream_symbols.edit', @currentModel
# New Route
App.DreamSymbolsNewRoute = Ember.Route.extend
model: ->
@store.createRecord('dream_symbol')
actions:
cancel: ->
@transitionTo 'dream_symbols.index'
save: ->
route = @
@currentModel.save().then (symbol)->
route.transitionTo 'dream_symbols.show', symbol
# Edit Route
App.DreamSymbolsEditRoute = Ember.Route.extend
model: (params)->
@store.find 'dream_symbol', params.id
actions:
cancel: ->
@currentModel.rollback()
@transitionTo 'dream_symbols.show', @currentModel
save: ->
route = @
@currentModel.save().then (symbol)->
route.transitionTo 'dream_symbols.show', symbol
delete: ->
console.log 'delete'
symbol = @store.find 'dream_symbol', 7
symbol.destroyRecord()
@transitionTo 'dream_symbols.index'
# symbol = @get 'model'
# symbol.destroyRecord()
# app/assets/javascripts/ember-app/templates/dream_symbols/edit.js.coffee
%h1
%i.fa.fa-pencil
Editing
= hb 'name'
%hr
%form.form-horizontal
= hb 'dream-symbol-form symbol=model'
.form-group
.col-sm-offset-2.col-sm-10
.btn-group
%btn.btn.btn-primary{ _action: 'save' }
Save
%btn.btn.btn-default{ _action: 'cancel' }
Cancel
%btn.btn.btn-default{ _action: 'delete' }
Delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment