Created
April 15, 2015 12:45
-
-
Save marvinosswald/6d11c40fc1ae1e194d58 to your computer and use it in GitHub Desktop.
How to access a model assigned by the controller from an action
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
import Ember from "ember"; | |
export default Ember.Route.extend({ | |
setupController:function(controller){ | |
if(sessionStorage.user){ | |
var user = JSON.parse(sessionStorage.user); | |
if(!user){ | |
this.transitionTo('login'); | |
}else{ | |
//way to go | |
controller.set('user', user); | |
controller.set('categories', this.store.find('category')); | |
controller.set('events', this.store.find('event')); | |
controller.set('newCatForm',this.store.createRecord('category')); | |
} | |
}else{ | |
this.transitionTo('login'); | |
} | |
}, | |
actions:{ | |
newCat:function(category){ | |
category.save(); | |
this.get('controller').set('newCatForm',this.store.createRecord('category')); | |
}, | |
editCat:function(id){ | |
//Not working code: | |
//need to get one of the records stored in categories and set it as editCatForm.. | |
var cat = this.controller.get('categories')[id]; | |
console.log(cat); | |
this.get('controller').set('editCatForm',cat); | |
$('#modEditCat').modal('show'); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment