Skip to content

Instantly share code, notes, and snippets.

@marvinosswald
Created April 15, 2015 12:45
Show Gist options
  • Save marvinosswald/6d11c40fc1ae1e194d58 to your computer and use it in GitHub Desktop.
Save marvinosswald/6d11c40fc1ae1e194d58 to your computer and use it in GitHub Desktop.
How to access a model assigned by the controller from an action
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